- tensor_reshape()将原始张量修改为指定形状大小的张量。
- tensor_transpose()函数将原始张量的维度进行调换。
import torch
import numpy as np
def tensor_reshape():
arr = np.array([[[1, 2, 3], [4, 5, 6], [7, 8, 9]],
[[1, 2, 3], [4, 5, 6], [7, 8, 9]],
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]])
t = torch.tensor(arr)
t1 = torch.reshape(t,(-1,1))
print(t1.shape)
def tensor_transpose():
arr = np.array([[[1, 2, 3,4], [4, 5, 6,7], [7, 8, 9,10]],
[[1, 2, 3,4], [4, 5, 6,7], [7, 8, 9,10]],
[[1, 2, 3,4], [4, 5, 6,7], [7, 8, 9,10]]])
print(arr)
t = torch.tensor(arr)
t1 = torch.transpose(t,0,2)
print(t1,t1.shape)
if __name__ == '__main__':
# tensor_reshape()
tensor_transpose()
最后
以上就是花痴早晨最近收集整理的关于pytorch(6)tensor_reshape()和tensor_transpose()函数的全部内容,更多相关pytorch(6)tensor_reshape()和tensor_transpose()函数内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复