torch学习笔记--tensor介绍2,对tensor的结构
本章将介绍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()