pytorch中reshape和transpose对比

import numpy as np
import torch
tensor=torch.randn(2,3)
print("tensor:\n",tensor)
print("2D\n")
print("transpose-fun:\n",torch.transpose(tensor,0,1))
print("2d-transposition:\n",torch.t(tensor))
print("reshape:\n",torch.reshape(tensor,(tensor.size()[1],tensor.size()[0])))
print("多维\n")
tensor1=torch.randn(2,3,2)
print("tensor1:\n",tensor1)
print("array1:\n",tensor1.numpy())
print("transpose:\n",torch.transpose(tensor1,0,1))

你可能感兴趣的:(pytorch中reshape和transpose对比)