eye
Return a 2-D array in the specified format with ones on the diagonal and zeros elsewhere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N |
int
|
Number of rows in the output. |
required |
M |
int
|
Number of columns in the output. If None, defaults to |
None
|
k |
int
|
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. |
0
|
dtype |
data - type
|
Data-type of the returned array. |
float
|
format |
str
|
A format string. |
'coo'
|
Returns:
| Name | Type | Description |
|---|---|---|
I |
SparseArray of shape (N, M)
|
An array where all elements are equal to zero, except for the |
Examples:
>>> eye(2, dtype=int).todense()
array([[1, 0],
[0, 1]])
>>> eye(3, k=1).todense()
array([[0., 1., 0.],
[0., 0., 1.],
[0., 0., 0.]])
Source code in sparse/numba_backend/_common.py
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 | |