numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
eye(N, M=None, k=0, dtype=<class 'float'>, order='C', *, like=None)

Parameters

N : int

Number of rows in the output.

M : int, optional

Number of columns in the output. If None, defaults to N.

k : int, optional

Index of the diagonal: 0 (the default) refers to the main diagonal, a positive value refers to an upper diagonal, and a negative value to a lower diagonal.

dtype : data-type, optional

Data-type of the returned array.

order : {'C', 'F'}, optional

Whether the output should be stored in row-major (C-style) or column-major (Fortran-style) order in memory.

versionadded
like : array_like

Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like supports the __array_function__ protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument.

versionadded

Returns

I : ndarray of shape (N,M)

An array where all elements are equal to zero, except for the k-th diagonal, whose values are equal to one.

Return a 2-D array with ones on the diagonal and zeros elsewhere.

See Also

diag

diagonal 2-D array from a 1-D array specified by the user.

identity

(almost) equivalent function

Examples

>>> np.eye(2, dtype=int)
array([[1, 0],
       [0, 1]])
>>> np.eye(3, k=1)
array([[0.,  1.,  0.],
       [0.,  0.,  1.],
       [0.,  0.,  0.]])
See :

Back References

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

scipy.linalg._decomp_update.qr_insert dask.array.reductions.trace dask.array.ufunc.conjugate scipy.linalg._solvers.solve_continuous_lyapunov dask.array.ufunc.logical_xor scipy.linalg._decomp_lu.lu_factor scipy.sparse.linalg._eigen.arpack.arpack.eigsh dask.array.ufunc.fmin dask.array.ufunc.minimum dask.array.ufunc.fmax scipy.signal._bsplines.spline_filter scipy.linalg._solvers.solve_discrete_lyapunov dask.array.routines.shape scipy.fft._basic.ifftn scipy.optimize._qap.quadratic_assignment scipy.fft._basic.ifft2 scipy.linalg._decomp_update.qr_delete scipy.linalg._decomp_update.qr_update dask.array.routines.count_nonzero scipy.sparse.linalg._eigen.arpack.arpack.eigs scipy.linalg._decomp_qr.qr_multiply dask.array.ufunc.maximum

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 : /numpy/lib/twodim_base.py#161
type: <class 'function'>
Commit: