pytorch学习笔记——常用函数

torch.softmax()
torch.reduce_max()
torch.pow()
torch.subtrack()=torch.sub()
torch.div()=torch.divide()
torch.gather()
torch.log()
pytorch常用计算

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PyTorch中,可以使用torch.nn.functional.softmax()函数来实现Softmax函数的计算。该函数的接口定义为torch.nn.functional.softmax(input, dim=None, _stacklevel=3, dtype=None)。 Softmax函数的核心在于对输入的张量进行归一化操作,将每个元素的值转化为一个(0, 1)之间的概率值,使得所有元素的概率和为1。Softmax函数的实现可以通过指定dim参数来对特定维度上的元素进行归一化操作。 以下是一个使用Softmax函数的例子: import torch import torch.nn.functional as F # 定义输入张量 input_tensor = torch.tensor([1.0, 2.0, 3.0]) # 对输入张量应用Softmax函数 output_tensor = F.softmax(input_tensor, dim=0) # 输出结果 print(output_tensor) 在上述例子中,我们定义了一个输入张量input_tensor,然后使用F.softmax()函数对其进行Softmax操作,指定dim=0表示对张量的第一个维度进行归一化操作。最后打印输出结果。请注意,Softmax函数返回的是一个概率分布,代表了每个元素被分配到每个类别的概率。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [【Pytorch基础】torch.nn.functional.softmax介绍](https://blog.csdn.net/zfhsfdhdfajhsr/article/details/124141658)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [PyTorch学习笔记 —— Softmax函数](https://blog.csdn.net/ProQianXiao/article/details/102893139)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值