本文簡要介紹 python 語言中 scipy.io.mmread
的用法。
用法:
scipy.io.mmread(source)#
將矩陣市場 file-like ‘source’ 的內容讀取到矩陣中。
- source: str 或 file-like
Matrix Market 文件名(擴展名 .mtx、.mtz.gz)或打開 file-like 對象。
- a: ndarray 或coo_matrix
密集或稀疏矩陣取決於矩陣市場文件中的矩陣格式。
參數 ::
返回 ::
注意:
例子:
>>> 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)
以 COO 格式的稀疏矩陣形式返回數據。>>> m = mmread(StringIO(text)) >>> m <5x5 sparse matrix of type '<class 'numpy.float64'>' with 7 stored elements in COOrdinate format> >>> m.A 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.]])
該方法是線程化的。默認線程數等於係統中CPU的數量。使用threadpoolctl覆蓋:
>>> import threadpoolctl >>> >>> with threadpoolctl.threadpool_limits(limits=2): ... m = mmread(StringIO(text))
相關用法
- Python SciPy io.mminfo用法及代碼示例
- Python SciPy io.mmwrite用法及代碼示例
- Python SciPy io.whosmat用法及代碼示例
- Python SciPy io.savemat用法及代碼示例
- Python SciPy io.loadmat用法及代碼示例
- Python SciPy io.netcdf_file用法及代碼示例
- Python SciPy io.hb_read用法及代碼示例
- Python SciPy io.FortranFile用法及代碼示例
- Python SciPy io.readsav用法及代碼示例
- Python SciPy io.hb_write用法及代碼示例
- Python SciPy interpolate.make_interp_spline用法及代碼示例
- Python SciPy interpolate.krogh_interpolate用法及代碼示例
- Python SciPy interpolative.reconstruct_matrix_from_id用法及代碼示例
- Python SciPy interpolate.InterpolatedUnivariateSpline用法及代碼示例
- Python SciPy interpolate.BSpline用法及代碼示例
- Python SciPy integrate.quad_vec用法及代碼示例
- Python SciPy interpolative.reconstruct_interp_matrix用法及代碼示例
- Python SciPy interpolate.LSQSphereBivariateSpline用法及代碼示例
- Python SciPy interpolate.griddata用法及代碼示例
- Python SciPy integrate.cumulative_trapezoid用法及代碼示例
- Python SciPy interpolate.splder用法及代碼示例
- Python SciPy interpolate.LinearNDInterpolator用法及代碼示例
- Python SciPy interpolate.PPoly用法及代碼示例
- Python SciPy interpolate.NdBSpline用法及代碼示例
- Python SciPy interpolate.pade用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.io.mmread。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。