Torch.arange in [start, end]

As torch.range is deprecated, how do I get a 1-D tensor in [start, end] with torch.arange

>>> torch.arange(-1.0,1.0,5)
torch([-1.0000, -0.5000, 0.0000, -0.5000])

>>> torch.range(-1.0,1.0,5)
torch([-1.0000, -0.5000, 0.0000, -0.5000, 1.0000])

without adding step value to end parameters in torch.arange? Any elegant way?

>>> step = 0.5
>>> torch.arange(-1.0,1.0+step,5)
torch([-1.0000, -0.5000, 0.0000, -0.5000, 1.0000])
1 Like

if you want end to be included, torch.linspace is the function that would do what you want more precisely – by definition: https://pytorch.org/docs/stable/torch.html?highlight=linspace#torch.linspace

3 Likes