import torch import numpy as np a = np.array([1, 2, 3]) t = torch.as_tensor(a) print(t) t[0] = -1 a
将numpy转为tensor也可以使用t = torch.from_numpy(a)
import torch import numpy as np a = np.array([1, 2, 3]) t = torch.as_tensor(a) print(t) t[0] = -1 a
将numpy转为tensor也可以使用t = torch.from_numpy(a)