scipy 1.8.0 Pypi GitHub Homepage
Other Docs
ParametersBackRef
eye(m, n=None, k=0, dtype=<class 'float'>, format=None)

Returns a sparse (m x n) matrix where the kth diagonal is all ones and everything else is zeros.

Parameters

m : int

Number of rows in the matrix.

n : int, optional

Number of columns. Default: m.

k : int, optional

Diagonal to place ones on. Default: 0 (main diagonal).

dtype : dtype, optional

Data type of the matrix.

format : str, optional

Sparse format of the result, e.g., format="csr", etc.

Sparse matrix with ones on diagonal

Examples

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

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.convert_matrix.from_scipy_sparse_array networkx.convert_matrix.from_scipy_sparse_matrix scipy.sparse._construct.eye

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/sparse/_construct.py#222
type: <class 'function'>
Commit: