bundles / scipy 1.17.1 / scipy / sparse / _construct / identity
function
scipy.sparse._construct:identity
source: /scipy/sparse/_construct.py :547
Signature
def identity ( n , dtype = d , format = None ) Summary
Identity matrix in sparse format
Extended Summary
Returns an identity matrix with shape (n, n) using a given sparse format and dtype. This differs from eye_array in that it has a square shape with ones only on the main diagonal. It is thus the multiplicative identity. eye_array allows rectangular shapes and the diagonal can be offset from the main one.
Parameters
n: intShape of the identity matrix.
dtype: dtype, optionalData type of the matrix
format: str, optionalSparse format of the result, e.g., format="csr", etc.
Returns
new_matrix: sparse matrixA square sparse matrix with ones on the main diagonal and zeros elsewhere.
Examples
import scipy as sp
✓sp.sparse.identity(3).toarray() sp.sparse.identity(3, dtype='int8', format='dia') sp.sparse.eye_array(3, dtype='int8', format='dia')✗
See also
- eye
Sparse matrix of chosen shape with ones on a specified diagonal.
- eye_array
Sparse array of chosen shape with ones on a specified diagonal.
Aliases
-
scipy.sparse.identity