Eine Liste der dünn besetzte Matrizen, und Wege, die in ein Array oder spärliche Matrix (oder nicht) Drehen:
In [916]: alist=[sparse.random(1,10,.2, format='csr') for _ in range(3)]
In [917]: alist
Out[917]:
[<1x10 sparse matrix of type '<class 'numpy.float64'>'
with 2 stored elements in Compressed Sparse Row format>,
<1x10 sparse matrix of type '<class 'numpy.float64'>'
with 2 stored elements in Compressed Sparse Row format>,
<1x10 sparse matrix of type '<class 'numpy.float64'>'
with 2 stored elements in Compressed Sparse Row format>]
machen eine richtige Sparse-Matrix (2d):
In [918]: sparse.vstack(alist)
Out[918]:
<3x10 sparse matrix of type '<class 'numpy.float64'>'
with 6 stored elements in Compressed Sparse Row format>
Objekt Array von Matrizen - schlecht
In [919]: np.array(alist)
Out[919]:
array([ <1x10 sparse matrix of type '<class 'numpy.float64'>'
with 2 stored elements in Compressed Sparse Row format>,
<1x10 sparse matrix of type '<class 'numpy.float64'>'
with 2 stored elements in Compressed Sparse Row format>,
<1x10 sparse matrix of type '<class 'numpy.float64'>'
with 2 stored elements in Compressed Sparse Row format>], dtype=object)
der Versuch, ein float-Array zu machen - Ihr Fehler
In [920]: np.array(alist, float)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-920-52d4689fa7b3> in <module>()
----> 1 np.array(alist, float)
ValueError: setting an array element with a sequence.
Der Klassifikator versucht wahrscheinlich, die Liste in ein Array umzuwandeln, z. 'np.asarray (X_zug)'. Wie ist die Form der Matrixelemente? Kann die Liste mit 'sparse.vstack' in eine große Sparse-Matrix umgewandelt werden? – hpaulj
Wenn Sie nach einem Fehler wie diesem fragen, sollten Sie, um höflich zu sein, Informationen darüber geben, wo er aufgetreten ist. Das ist ein Stack-Trace und wenn möglich mehr Informationen über die vermuteten Problemvariablen. – hpaulj
Ihre Methode funktioniert! Danke! und danke für die Köpfe, ich werde daran denken, die Protokolle aufzunehmen. – psiyan