Pytorch tensor 矩阵转置方法

Pytorch tensor 矩阵转置方法

直接贴官方文档啦

多维矩阵转置:

torch.transpose(input, dim0, dim1) → Tensor

- input (Tensor) – the input tensor.
- dim0 (int) – the first dimension to be transposed
- dim1 (int) – the second dimension to be transposed

例子:

x = torch.randn(2, 3)
x
'''
tensor([[ 1.0028, -0.9893,  0.5809],
        [-0.1669,  0.7299,  0.4942]])
'''
torch.transpose(x, 0, 1)
'''
tensor([[ 1.0028, -0.1669],
        [-0.9893,  0.7299],
        [ 0.5809,  0.4942]])
'''

二维及以下矩阵转置:

torch.t(input) → Tensor
- input (Tensor) – the input tensor.

例子:

x = torch.randn(())
x
'''
tensor(0.1995)
'''
torch.t(x)
x = torch.randn(3)
x
'''
tensor(0.1995)
'''
torch.t(x)
'''
tensor([ 2.4320, -0.4608,  0.7702])
'''
x = torch.randn(2, 3)
x
'''
tensor([[ 0.4875,  0.9158, -0.5872],
        [ 0.3938, -0.6929,  0.6932]])
'''
torch.t(x)
'''
tensor([[ 0.4875,  0.3938],
        [ 0.9158, -0.6929],
        [-0.5872,  0.6932]])
'''

1) https://pytorch.org/docs/stable/generated/torch.transpose.html
2) https://pytorch.org/docs/stable/generated/torch.t.html#torch.t

版权声明:本文《Pytorch tensor 矩阵转置方法》为网站老表爱技术作者「oldwatch」的原创文章,请联系微信:pythonbrief 获取转载权限,或者提问交流。
原文链接:https://python-brief.com/147.html
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇