1.將numpy矩陣轉換爲Tensor張量code
sub_ts = torch.from_numpy(sub_img) #sub_img爲numpy類型
2.將Tensor張量轉化爲numpy矩陣blog
sub_np1 = sub_ts.numpy() #sub_ts爲tensor張量
3.將numpy轉換爲Variableclass
sub_va = Variable(torch.from_numpy(sub_img))
4.將Variable張量轉化爲numpynumpy
sub_np2 = sub_va.data.numpy()