torch.range()和torch.arange()

示例文件 test.py

import torch

x = torch.arange(0, 6)
print(x)
print(x.type())
y = torch.range(0, 6)
print(y)
print(y.type())

终端命令行和运行结果

python test.py
tensor([0, 1, 2, 3, 4, 5])
torch.LongTensor
tensor([0., 1., 2., 3., 4., 5., 6.])
torch.FloatTensor

从运算结果来看:

torch.arange(start=1, end=6)的结果不会包含end,类型是torch.LongTensor。

torch.range(start=1, end=6) 的结果会包含end,类型是torch.FloatTensor。

此外,arange(6)相当于arange(0, 6),而range(6)不能使用。

你可能感兴趣的:(Pytorch)