本文簡要介紹 python 語言中 scipy.sparse.load_npz
的用法。
用法:
scipy.sparse.load_npz(file)#
使用
.npz
格式從文件加載稀疏矩陣。- file: str 或 file-like 對象
將加載數據的文件名(字符串)或打開的文件(file-like 對象)。
- result: csc_matrix、csr_matrix、bsr_matrix、dia_matrix或coo_matrix
包含加載數據的稀疏矩陣。
- 操作係統錯誤
如果輸入文件不存在或無法讀取。
參數 ::
返回 ::
拋出 ::
例子:
將稀疏矩陣存儲到磁盤,然後再次加載:
>>> import numpy as np >>> import scipy.sparse >>> sparse_matrix = scipy.sparse.csc_matrix(np.array([[0, 0, 3], [4, 0, 0]])) >>> sparse_matrix <2x3 sparse matrix of type '<class 'numpy.int64'>' with 2 stored elements in Compressed Sparse Column format> >>> sparse_matrix.toarray() array([[0, 0, 3], [4, 0, 0]], dtype=int64)
>>> scipy.sparse.save_npz('/tmp/sparse_matrix.npz', sparse_matrix) >>> sparse_matrix = scipy.sparse.load_npz('/tmp/sparse_matrix.npz')
>>> sparse_matrix <2x3 sparse matrix of type '<class 'numpy.int64'>' with 2 stored elements in Compressed Sparse Column format> >>> sparse_matrix.toarray() array([[0, 0, 3], [4, 0, 0]], dtype=int64)
相關用法
- Python SciPy sparse.isspmatrix用法及代碼示例
- Python SciPy sparse.save_npz用法及代碼示例
- Python SciPy sparse.issparse用法及代碼示例
- Python SciPy sparse.coo_matrix用法及代碼示例
- Python SciPy sparse.isspmatrix_csc用法及代碼示例
- Python SciPy sparse.isspmatrix_csr用法及代碼示例
- Python SciPy sparse.tril用法及代碼示例
- Python SciPy sparse.coo_array用法及代碼示例
- Python SciPy sparse.dia_array用法及代碼示例
- Python SciPy sparse.bmat用法及代碼示例
- Python SciPy sparse.hstack用法及代碼示例
- Python SciPy sparse.rand用法及代碼示例
- Python SciPy sparse.dia_matrix用法及代碼示例
- Python SciPy sparse.find用法及代碼示例
- Python SciPy sparse.isspmatrix_dia用法及代碼示例
- Python SciPy sparse.isspmatrix_lil用法及代碼示例
- Python SciPy sparse.csc_matrix用法及代碼示例
- Python SciPy sparse.block_diag用法及代碼示例
- Python SciPy sparse.diags用法及代碼示例
- Python SciPy sparse.vstack用法及代碼示例
- Python SciPy sparse.dok_matrix用法及代碼示例
- Python SciPy sparse.kron用法及代碼示例
- Python SciPy sparse.random用法及代碼示例
- Python SciPy sparse.identity用法及代碼示例
- Python SciPy sparse.spdiags用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.sparse.load_npz。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。