看代码,tensor转numpy:
a = torch.ones(2,2)
b = a.numpy()
c=np.array(a) #也可以转numpy数组
print(type(a))
print(type(b))
print(a)
print(b)
输出为:
tensor([[1., 1.],
[1., 1.]])
[[1. 1.]
[1. 1.]]
numpy转tensor:
import torch
import numpy as np
a = np.ones(5)
b = torch.
2021-09-23 21:37:26
29KB
c
mp
ns
1