1、最值得注意的区别
# torch.arange()
x = torch.arange(1.0,6.0)
print(x)
输出:tensor([1., 2., 3., 4., 5.])
# torch.range()
y = torch.range(1.0,6.0)
print(y)
输出:tensor([1., 2., 3., 4., 5., 6.])
torch.arange(start=1.0, end=6.0)
的结果不包括end
torch.range(start=1.0, end=6.0)
的结果包括end
2、推荐使用torch.arange()
很显然,torch.arange()
兼容更多种类的参数。