scipy.sparse.eye

scipy.sparse.eye(m, n=None, k=0, dtype=<class 'float'>, format=None)[源代码]

对角线上的稀疏矩阵

返回稀疏(M X N)矩阵,其中第k条对角线全为1,其他所有内容均为0。

参数
m集成

矩阵中的行数。

n整型,可选

列数。默认值: m

k整型,可选

对角线放置一个。默认值:0(主对角线)。

dtype数据类型,可选

矩阵的数据类型。

format字符串,可选

结果的稀疏格式,例如,FORMAT=“CSR”等。

示例

>>> 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>