Numpy 的 identity(~)
方法返回指定大小的單位矩陣。
參數
1. n
| int
矩陣的大小(即行數和列數)。
2. dtype
| string
或 type
| optional
返回的單位矩陣所需的數據類型。默認情況下,dtype=Float
。
返回值
表示單位矩陣的 2D Numpy 數組。
例子
基本用法
創建大小為 3 的單位矩陣:
np.identity(3)
array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])
要創建 int64
類型的單位矩陣:
np.identity(3, dtype="int64")
array([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])
相關用法
- Python numpy matrix identity()用法及代碼示例
- Python id()用法及代碼示例
- Python id方法用法及代碼示例
- Python NumPy itemset方法用法及代碼示例
- Python import__用法及代碼示例
- Python isinstance方法用法及代碼示例
- Python BeautifulSoup insert方法用法及代碼示例
- Python itertools.takewhile用法及代碼示例
- Python ipaddress.collapse_addresses用法及代碼示例
- Python ipaddress.IPv4Address.reverse_pointer用法及代碼示例
- Python io.text_encoding用法及代碼示例
- Python string isidentifier()用法及代碼示例
- Python numpy irr用法及代碼示例
- Python ipaddress.IPv4Address.__format__用法及代碼示例
- Python calendar isleap()用法及代碼示例
- Python math isclose()用法及代碼示例
- Python NumPy isalnum方法用法及代碼示例
- Python NumPy isnat方法用法及代碼示例
- Python string isupper()用法及代碼示例
- Python itertools.cycle用法及代碼示例
- Python itertools.dropwhile用法及代碼示例
- Python scipy integrate.trapz用法及代碼示例
- Python itertools.repeat用法及代碼示例
- Python ipaddress.IPv4Network.supernet用法及代碼示例
- Python string isalnum()用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | identity method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。