torch.nn.functional.softmax(input) 维度学习

1. softmax(input, dim=none)

import torch.nn.functional as F
import torch
a = torch.randn((2,3,2))
b = F.softmax(a,1)
c = F.softmax(a,2)
d = F.softmax(a,0)
"""
a
Out[5]: 
tensor([[[ 1.8777,  0.8479],
         [-0.7809,  2.1866],
         [-0.5761,  0.6063]],

        [[ 1.5799, -0.7697],
         [-1.2000, -0.6929],
         [-0.2571, -0.9807]]])

b   #F.softmax(a,1)
Out[6]: 
tensor([[[0.8650, 0.1786],
         [0.0606, 0.6811],
         [0.0744, 0.1403]],

        [[0.8188, 0.3461],
         [0.0508, 0.3737],
         [0.1304, 0.2802]]])
c   #F.softmax(a,2)
Out[8]: 
tensor([[[0.7369, 0.2631],
         [0.0489, 0.9511],
         [0.2346, 0.7654]],

        [[0.9129, 0.0871],
         [0.3759, 0.6241],
         [0.6734, 0.3266]]])
d  #F.softmax(a,0)
Out[12]: 
tensor([[[0.5739, 0.8345],
         [0.6033, 0.9468],
         [0.4209, 0.8302]],

        [[0.4261, 0.1655],
         [0.3967, 0.0532],
         [0.5791, 0.1698]]])
"""

2 dim

a.size()
#Out[13]: torch.Size([2, 3, 2])

(1)dim=1时

a是3维结构,dim=0,1,2 代表三个维度的索引。dim=1时,在如图的方向上进行softmax运算。
在这里插入图片描述

(2)dim=2时

在这里插入图片描述

(3)dim=0时

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值