pytorch:中numpy数组转Tensor: Expected object of backend CUDA and type float

在pytorch中,想要将numpy数组x_n转化为Tensor,并指定dtype,便于训练,于是如下:

x_t=torch.Tensor(x_n,dtype=torch.float32)

若是使用GPU,则需要加上cuda:

x_t=x_t.cuda()

你可能感兴趣的:(pytorch:中numpy数组转Tensor: Expected object of backend CUDA and type float)