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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。