open3d.core.Tensor
类的eye
函数返回指定形状的单位矩阵。
open3d.core.Tensor.eye(N: int, dtype: open3d.core.Dtype = open3d.core.Dtype.Float32,
device: Optional[open3d.core.Device] = None) -> open3d.core.Tensor
N
(int):矩阵的大小。dtype
(open3d.core.Dtype,可选):矩阵元素的数据类型。默认为float32
。device
(open3d.core.Device,可选):指定Tensor的设备。默认为None
,表示使用默认设备。返回指定形状的单位矩阵(二维张量)。
import open3d.core as o3c
# 创建一个2x2的浮点类型单位矩阵
tensor = o3c.Tensor.eye(2, dtype=o3c.Dtype.Float32)
print(tensor)
# 创建一个3x3的整数类型单位矩阵
tensor = o3c.Tensor.eye(3, dtype=o3c.Dtype.Int32)
print(tensor)
输出:
[1, 0]
[0, 1]
shape: (2, 2), dtype: Float32, cpu, id=140009130156368
[int32[1, 0, 0],
int32[0, 1, 0],
int32[0, 0, 1]]
shape: (3, 3), dtype: Int32, cpu, id=140009130032880
device
参数,则需要确保当前设备上存在相应类型的运算库(如CUDA)。N
参数必须是正整数;否则,会引发ValueError
异常。