numpy.matlib.identity#

matlib.identity(n, dtype=None)[source]#

傳回給定大小的單位方陣。

參數:
nint

傳回的單位矩陣的大小。

dtype資料型別,選用

輸出資料型別。預設為 float

傳回值:
out矩陣

n x n 矩陣,其主對角線設為 1,所有其他元素為零。

另請參閱

numpy.identity

等效的陣列函式。

matlib.eye

更通用的矩陣單位函式。

範例

>>> import numpy.matlib
>>> np.matlib.identity(3, dtype=int)
matrix([[1, 0, 0],
        [0, 1, 0],
        [0, 0, 1]])