本文简要介绍 python 语言中 scipy.sparse.eye
的用法。
用法:
scipy.sparse.eye(m, n=None, k=0, dtype=<class 'float'>, format=None)#
对角线上的稀疏矩阵
返回一个稀疏 (m x n) 矩阵,其中第 k 个对角线全为 1,其他全为 0。
- m: int
矩阵中的行数。
- n: 整数,可选
列数。默认值:米。
- k: 整数,可选
放置的对角线。默认值:0(主对角线)。
- dtype: dtype,可选
矩阵的数据类型。
- format: str,可选
结果的稀疏格式,例如format=”csr”等。
参数 ::
例子:
>>> import numpy as np >>> from scipy import sparse >>> sparse.eye(3).toarray() array([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]]) >>> sparse.eye(3, dtype=np.int8) <3x3 sparse matrix of type '<class 'numpy.int8'>' with 3 stored elements (1 diagonals) in DIAgonal format>
相关用法
- 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.eye。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。