numpy.matlib.eye#

matlib.eye(n, M=None, k=0, dtype=<class 'float'>, order='C')[源]#

返回一个对角线上为一,其他位置为零的矩阵。

参数:
nint

输出中的行数。

Mint, optional

输出中的列数,默认为 n

kint, optional

对角线的索引:0 表示主对角线,正值表示上对角线,负值表示下对角线。

dtypedtype, optional

返回矩阵的数据类型。

order{‘C’, ‘F’}, optional

输出在内存中是以行主序(C 风格)还是列主序(Fortran 风格)存储。

返回值:
I矩阵

一个 n x M 矩阵,其中所有元素都为零,除了第 k 条对角线上的值为一。

另请参阅

numpy.eye

等效的数组函数。

identity

方单位矩阵。

示例

>>> import numpy.matlib
>>> np.matlib.eye(3, k=1, dtype=float)
matrix([[0.,  1.,  0.],
        [0.,  0.,  1.],
        [0.,  0.,  0.]])