torch.arange

torch.arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor

返回一个一维向量,其大小为\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil ,取值区间为[start, end) ,从start开始,以step为步长增加,直到end结束(不包括end) 

例子:

>>> torch.arange(5)
tensor([ 0,  1,  2,  3,  4])
>>> torch.arange(1, 4)
tensor([ 1,  2,  3])
>>> torch.arange(1, 2.5, 0.5)
tensor([ 1.0000,  1.5000,  2.0000])

 


版权声明:本文为Elvira521yan原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。