本文簡要介紹 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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。