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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。