https://docs.scipy.org/doc/numpy/reference/generated/numpy.eye.html
对角矩阵
Return a 2-D array with ones on the diagonal and zeros elsewhere.
返回一个 对角线是1,其余是0的 2维数组。
参数
- N (行)
- M (列)
- K (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 数据类型
- order (Whether the output should be stored in row-major (C-style) or column-major (Fortran-style) order in memory)
例子
N+dtype
1 | import numpy as np |
1 | np.eye(3, dtype=int) |
1 | np.eye(4, dtype=int) |
N+M
1 | np.eye(2, 2) |
1 | np.eye(3, 6) |
N+K
1 | np.eye(3, k=1) |
1 | np.eye(4, k=1) |