本文简要介绍 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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。