torch与numpy

因为在编程的过程中,总是忘记两者该如何转换,下面记录笔记,方便查看!

1、torch 转 numpy

image_te = [1,2,3,4,5,6]
img = np.array(image_te)
img.shape()
img = torch.tensor(img)#此处就转换成了torch,可以往网络模型中传送了
import matplotlib.pyplot as plt
plt.figure('yy')
plt.axis('on')
plt.title('zmy')
plt.imshow(img)
plt.show()

2、torch 转 numpy

img = torch.tensor(img)
img = np.array(img)#这里就直接成了array类型

猜你喜欢

转载自blog.csdn.net/TTLoveYuYu/article/details/112280725