bundles / scipy 1.18.0 / scipy / sparse / _construct / eye_array
function
scipy.sparse._construct:eye_array
source: /scipy/sparse/_construct.py:632
Signature
def eye_array(m, n = None, *, k = 0, dtype = <class 'float'>, format = None)Summary
Sparse array of chosen shape with ones on the kth diagonal and zeros elsewhere.
Extended Summary
Return a sparse array with ones on diagonal. Specifically a sparse array (m x n) where the kth diagonal is all ones and everything else is zeros.
Parameters
m: intNumber of rows requested.
n: int, optionalNumber of columns. Default:
m.k: int, optionalDiagonal to place ones on. Default: 0 (main diagonal).
dtype: dtype, optionalData type of the array
format: str, optional (default: "dia")Sparse format of the result, e.g., format="csr", etc.
Returns
new_array: sparse arraySparse array of chosen shape with ones on the kth diagonal and zeros elsewhere.
Examples
import numpy as np import scipy as sp✓
sp.sparse.eye_array(3).toarray() sp.sparse.eye_array(3, dtype=np.int8)✗
<DIAgonal sparse array of dtype 'int8' with 3 stored elements (1 diagonals) and shape (3, 3)>
Aliases
scipy.sparse.eye_array