arange
方法创建一个与numpy中的arange
方法相同的一维张量,用于表示一个范围内的数字序列。
arange(start, stop=None, step=1.0, dtype=<class 'float'>)
start
:序列起始值。如果只提供一个参数,则从0开始。stop
:序列结束值。不包含此值。step
:值与值之间的步长。dtype
:张量的数据类型。返回一个一维张量,其范围由start
和stop
确定,步长为step
。
import open3d.core as o3c
# 创建包含从0到5(不包括5)之间整数的张量
tensor1 = o3c.Tensor.arange(5)
print(tensor1) # [0., 1., 2., 3., 4.]
# 创建包含从1到9(不包括9),间隔为2的张量
tensor2 = o3c.Tensor.arange(1, 9, 2)
print(tensor2) # [1., 3., 5., 7.]
# 创建包含从0到1(不包括1)之间,步长为0.1的张量
tensor3 = o3c.Tensor.arange(0, 1, 0.1)
print(tensor3) # [0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
start
和stop
必须是可比较的。