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
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 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 |
|