在Open3D中,open3d.core.Tensor类的sub方法表示两个张量相减的数字运算操作。
sub(other: open3d.core.Tensor) -> open3d.core.Tensor
返回一个新的张量,其值为将当前张量减去other张量后的结果。
import open3d.core as o3c
import numpy as np
# 创建两个形状相同的张量
a = o3c.Tensor(np.array([[1, 2], [2, 3]], dtype=np.float32))
b = o3c.Tensor(np.array([[1, 1], [1, 1]], dtype=np.float32))
# 相减
c = a.sub(b)
print("a = \n{}".format(a))
print("b = \n{}".format(b))
print("c = \n{}".format(c))
# 输出结果
# a =
# [[1. 2.]
# [2. 3.]]
# b =
# [[1. 1.]
# [1. 1.]]
# c =
# [[0. 1.]
# [1. 2.]]
在上面的示例中,我们通过open3d.core.Tensor的sub方法对两个相同形状的张量进行相减操作,得到了新的张量c,并输出了a、b、c的值。
如果other张量的形状与当前张量不同,将会抛出ValueError异常。