A RetroSearch Logo

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

Search Query:

Showing content from https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.eye_array.html below:

eye_array — SciPy v1.16.1 Manual

scipy.sparse.

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

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

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

Number of rows requested.

nint, optional

Number of columns. Default: m.

kint, optional

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

dtypedtype, optional

Data type of the array

formatstr, optional (default: “dia”)

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

Returns:
new_arraysparse array

Sparse 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()
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])
>>> sp.sparse.eye_array(3, dtype=np.int8)
<DIAgonal sparse array 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