bsparse.sparse.eye#

sparse.eye(shape, offset=0, dtype=<class 'float'>, format='coo')#

Create a sparse identity matrix of specified shape and dtype.

Parameters:
shapetuple[int, int]

The shape of the matrix.

offsetint, optional

The offset of the diagonal, by default 0.

dtypenp.dtype, optional

The data type of the matrix elements, by default float.

formatstr, optional

The sparse format of the matrix, by default “coo”.

Returns:
Sparse

A sparse identity matrix of specified shape and dtype.

Examples

>>> eye((3, 3))
COO(shape=(3, 3), nnz=3, dtype=float64)
>>> eye((3, 3), format="csr")
CSR(shape=(3, 3), nnz=3, dtype=float64)
>>> eye((3, 3)).toarray()
array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]])