Parameters:
n :[int] n * n维的输出数组
dtype :[可选,float(byDefault)]返回数组的数据类型。
Python
返回值:
n x n的单位数组,其主对角线设置为1,其他所有元素为0。
示例
# Python Programming illustrating# numpy.identity methodimport numpy as geek
# 2x2 matrix with 1's on main diagonal
b = geek.identity(2, dtype =float)print("Matrix b : \n", b)
a = geek.identity(4)print("\nMatrix a : \n", a)
Python
输出 :
Matrix b :[[1.0.][0.1.]]Matrix a :[[1.0.0.0.][0.1.0.0.][0.0.1.0.][0.0.0.1.]]