Use Tensor.cpu() to copy the tensor to host memory first. Tensor在进行numpy计算的时候需要与numpy()的格式进行转换 1.查看计算的tensor的位置信息。cpu tensor或者gpu tensor(cuda) 2.如果为cuda tensor,需要进行转换numpy格式(cpu tensor原理一样) 1)data.cpu().detach().numpy() #将data转换成cpu numpy格式 2)result.cuda() #将data的计算结果result转换回cuda tensor进行下一步计算