This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / sparse / _construct / eye

function

scipy.sparse._construct:eye

source: build-install/usr/lib/python3.14/site-packages/scipy/sparse/_construct.py:717

Signature

def eye(m, n = None, k = 0, dtype = <class 'float'>, format = None)

Summary

Sparse matrix of chosen shape with ones on the kth diagonal and zeros elsewhere.

Extended Summary

Returns a sparse matrix (m x n) 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.

Returns

new_matrix : sparse matrix

Sparse matrix of chosen shape with ones on the kth diagonaland zeros elsewhere.

Examples

import numpy as np
import scipy as sp
✓

See also

eye_array

Sparse array of chosen shape with ones on a specified diagonal.

Aliases

  • scipy.sparse.eye