Numpy转为Tensor
使用torch.from_numpy()
如
import torch
B = torch.from_numpy(A)
Tensor转为Numpy
使用data.numpy()
如
import torch
C = B.numpy()
可能会出现报错如下
TypeError: can’t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor
只要改为
C = B.cpu().numpy()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)