scipy.sparse.identity¶
- scipy.sparse.identity(n, dtype='d', format=None)[源代码]¶
稀疏格式单位矩阵
使用给定的稀疏格式和数据类型返回形状为(n,n)的单位矩阵。
- 参数
- n集成
单位矩阵的形状。
- dtype数据类型,可选
矩阵的数据类型
- format字符串,可选
结果的稀疏格式,例如,FORMAT=“CSR”等。
示例
>>> from scipy.sparse import identity >>> identity(3).toarray() array([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]]) >>> identity(3, dtype='int8', format='dia') <3x3 sparse matrix of type '<class 'numpy.int8'>' with 3 stored elements (1 diagonals) in DIAgonal format>