F.softmax

import torch
import torch.nn.functional as F
 
input = torch.randn(3,4)
print(input)
 
b = F.softmax(input,dim=0) # 按列SoftMax,列和为1
print('b',b)

c = F.softmax(input,dim=-2)   # 按行SoftMax,列和为1
print('c',c)

d = F.softmax(input,dim=1)   # 按行SoftMax,行和为1
print('d',d)

e = F.softmax(input,dim=-1)   # 按行SoftMax,行和为1
print('e',e)

tensor([[ 0.7782, -0.4178, -0.8316, -1.0575],
        [ 1.0279, -0.5515,  1.1533, -2.3556],
        [-1.4882,  0.6435, -1.7345, -1.7422]])
b tensor([[0.4189, 0.2099, 0.1152, 0.5627],
        [0.5377, 0.1836, 0.8382, 0.1536],
        [0.0434, 0.6065, 0.0467, 0.2837]])
c tensor([[0.4189, 0.2099, 0.1152, 0.5627],
        [0.5377, 0.1836, 0.8382, 0.1536],
        [0.0434, 0.6065, 0.0467, 0.2837]])
d tensor([[0.6017, 0.1820, 0.1203, 0.0960],
        [0.4213, 0.0868, 0.4776, 0.0143],
        [0.0910, 0.7672, 0.0712, 0.0706]])
e tensor([[0.6017, 0.1820, 0.1203, 0.0960],
        [0.4213, 0.0868, 0.4776, 0.0143],
        [0.0910, 0.7672, 0.0712, 0.0706]])
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值