scipy.io.
mmread#
- scipy.io.mmread(source, *, spmatrix=True)[Quelle]#
Liest den Inhalt einer Matrix-Market-Dateiähnlichen Quelle in eine Matrix ein.
- Parameter:
- sourcestr oder dateiähnlich
Matrix-Market-Dateiname (Erweiterungen .mtx, .mtz.gz) oder offenes dateiähnliches Objekt.
- spmatrixbool, optional (Standard: True)
Wenn
True, wird eine dünnecoo_matrixzurückgegeben. Andernfalls wird einecoo_arrayzurückgegeben.
- Rückgabe:
- andarray oder coo_array
Dichte oder dünne Matrix, abhängig vom Matrixformat in der Matrix-Market-Datei.
Hinweise
Geändert in Version 1.12.0: C++-Implementierung.
Beispiele
>>> from io import StringIO >>> from scipy.io import mmread
>>> text = '''%%MatrixMarket matrix coordinate real general ... 5 5 7 ... 2 3 1.0 ... 3 4 2.0 ... 3 5 3.0 ... 4 1 4.0 ... 4 2 5.0 ... 4 3 6.0 ... 4 4 7.0 ... '''
mmread(source)gibt die Daten als dünne Matrix im COO-Format zurück.>>> m = mmread(StringIO(text), spmatrix=False) >>> m <COOrdinate sparse array of dtype 'float64' with 7 stored elements and shape (5, 5)> >>> m.toarray() array([[0., 0., 0., 0., 0.], [0., 0., 1., 0., 0.], [0., 0., 0., 2., 3.], [4., 5., 6., 7., 0.], [0., 0., 0., 0., 0.]])
Diese Methode ist multithreaded. Die Standardanzahl von Threads entspricht der Anzahl der CPUs im System. Verwenden Sie threadpoolctl zum Überschreiben.
>>> import threadpoolctl >>> >>> with threadpoolctl.threadpool_limits(limits=2): ... m = mmread(StringIO(text), spmatrix=False)