本章将介绍tensor的结构与函数

torch.Tensor():返回一个空tensor。

torch.Tensor(tensor):返回一个拥有相同内存的tensor,类似于指针。不是重新开辟一个内存空间。

>x
  1   2   3   4   5
  6   7   8   9  10
 11  12  13  14  15
 16  17  18  19  20
[torch.DoubleTensor of size 4x5]
>y=x
>y
  1   2   3   4   5
  6   7   8   9  10
 11  12  13  14  15
 16  17  18  19  20
[torch.DoubleTensor of size 4x5]
>y[1][1]=3
>x
  3   2   3   4   5
  6   7   8   9  10
 11  12  13  14  15
 16  17  18  19  20
[torch.DoubleTensor of size 4x5]

  所以你打算复制tensor时候,你应该使用这样的方式:

y = torch.Tensor(x:size()):copy(x)

或者

y = x:clone()

 

相关文章:

  • 2021-06-20
  • 2021-07-14
  • 2021-11-19
  • 2022-12-23
  • 2021-11-29
  • 2021-12-31
  • 2021-05-29
  • 2021-07-01
猜你喜欢
  • 2022-12-23
  • 2022-01-18
  • 2021-09-25
  • 2022-12-23
  • 2021-08-24
  • 2021-06-30
  • 2021-12-11
相关资源
相似解决方案