numpy.identity(n,dtype = None):返回一个单位矩阵,即在主daignol上带有1的平方矩阵。
参数:
n : [int] Dimension n x n of output array dtype : [optional, float(by Default)] Data type of returned array.
返回值:
identity array of dimension n x n, with its main diagonal set to one, and all other elements 0.
# Python Programming illustrating
# numpy.identity method
import numpy as geek
# 2x2 matrix with 1's on main diagnol
b = geek.identity(2, dtype = float)
print("Matrix b : \n", b)
a = geek.identity(4)
print("\nMatrix a : \n", a)
输出:
Matrix b : [[ 1. 0.] [ 0. 1.]] Matrix a : [[ 1. 0. 0. 0.] [ 0. 1. 0. 0.] [ 0. 0. 1. 0.] [ 0. 0. 0. 1.]]
注意:
这些代码无法在online-ID上运行。请在您的系统上运行它们以探索其工作原理。
相关用法
注:本文由纯净天空筛选整理自 numpy.identity() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。