pytorch.range() 和 pytorch.arange()

>>> y=torch.range(1,6)
>>> y
tensor([1., 2., 3., 4., 5., 6.])
>>> y.dtype
torch.float32

>>> z=torch.arange(1,6)
>>> z
tensor([1, 2, 3, 4, 5])
>>> z.dtype
torch.int64

总结:

  1. torch.range(start=1, end=6) 的结果是会包含end的,
    torch.arange(start=1, end=6)的结果并不包含end
  2. 两者创建的tensor的类型也不一样。
发布了943 篇原创文章 · 获赞 136 · 访问量 33万+

猜你喜欢

转载自blog.csdn.net/weixin_36670529/article/details/105350158