我是靠谱客的博主 花痴早晨,这篇文章主要介绍pytorch(6)tensor_reshape()和tensor_transpose()函数,现在分享给大家,希望可以做个参考。

  1. tensor_reshape()将原始张量修改为指定形状大小的张量。
  2. 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()函数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部