A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://scipy.github.io/devdocs/reference/generated/scipy.sparse.eye.html below:

eye — SciPy v1.17.0.dev Manual

scipy.sparse.

eye#
scipy.sparse.eye(m, n=None, k=0, dtype=<class 'float'>, format=None)[source]#

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

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

Warning

This function returns a sparse matrix – not a sparse array. You are encouraged to use eye_array to take advantage of the sparse array functionality.

Parameters:
mint

Number of rows in the matrix.

nint, optional

Number of columns. Default: m.

kint, optional

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

dtypedtype, optional

Data type of the matrix.

formatstr, optional

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

Returns:
new_matrixsparse matrix

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

See also

eye_array

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

Examples

>>> import numpy as np
>>> import scipy as sp
>>> sp.sparse.eye(3).toarray()
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])
>>> sp.sparse.eye(3, dtype=np.int8)
<DIAgonal sparse matrix of dtype 'int8'
    with 3 stored elements (1 diagonals) and shape (3, 3)>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4