torch.max(input, dim)使用说明

pred = torch.max(input, dim)

返回每行(dim=1)或每列(dim=0)的最大值。

_, pred = torch.max(input, dim)

仅返回每行(dim=1)或每列(dim=0)中最大值所在位置。

示例:

import torch# 构造一个5x3随机初始化的矩阵
x = torch.rand(5, 3)
print('input: ', x)
print('-'*10)
y1 = torch.max(x, 1)
print('max by row: ', y1)
print('-'*10)
y2 = torch.max(x, 0)
print('max by col: ', y2)
print('-'*10)
_, y3 = torch.max(x, 1)
print('max index by row: ', y3)
print('-'*10)
_, y4 = torch.max(x, 0)
print('max index by col: ', y4)

输出结果:

input:  tensor([[0.5504, 0.3160, 0.2448],[0.8694, 0.3295, 0.2085],[0.5530, 0.9984, 0.3531],[0.2874, 0.1025, 0.9419],[0.0867, 0.4234, 0.8334]])
----------
max by row:  torch.return_types.max(
values=tensor([0.5504, 0.8694, 0.9984, 0.9419, 0.8334]),
indices=tensor([0, 0, 1, 2, 2]))
----------
max by col:  torch.return_types.max(
values=tensor([0.8694, 0.9984, 0.9419]),
indices=tensor([1, 2, 3]))
----------
max index by row:  tensor([0, 0, 1, 2, 2])
----------
max index by col:  tensor([1, 2, 3])

torch.max使用示例相关推荐

  1. PyTorch 笔记(08)— Tensor 比较运算(torch.gt、lt、ge、le、eq、ne、torch.topk、torch.sort、torch.max、torch.min)

    1. 常用函数 比较函数中有一些是逐元素比较,操作类似逐元素操作,还有一些类似归并操作,常用的比较函数如下表所示. 表中第一行的比较操作已经实现了运算符重载,因此可以使用 a>=b,a>b ...

  2. 如何使用PyTorch torch.max()

    In this article, we'll take a look at using the PyTorch torch.max() function. 在本文中,我们将介绍如何使用PyTorch ...

  3. torch.max()、expand()、expand_as()使用讲解

    在分类问题中,通常需要使用max()函数对softmax函数的输出值进行操作,求出预测值索引,然后与标签进行比对,计算准确率.下面讲解一下torch.max()函数的输入及输出值都是什么,便于我们理解 ...

  4. Pytorch view()、squeeze()、unsqueeze()、torch.max()

    本篇博客主要向大家介绍Pytorch中view().squeeze().unsqueeze().torch.max()函数,这些函数虽然简单,但是在 神经网络编程总却经常用到,希望大家看了这篇博文能够 ...

  5. torch.max和torch.softmax

    softmax 先exp,再在上面求总和的百分比 解决了负数相互抵消的问题. if __name__ == '__main__':import torchimport torch.nn.functio ...

  6. torch max 判断与筛选

    判断max是否大于0:item()后,就变成了一个值了, import torch y=torch.Tensor(1,2,3) if torch.max(y>=2).item(): print( ...

  7. Pytorch学习-torch.max()和min()深度解析

    Pytorch学习-torch.max和min深度解析 max的使用 min同理 dim参数理解 二维张量使用max() 三维张量使用max() max的使用 min同理 参考链接: 参考链接: 对于 ...

  8. PyTorch基础(十)----- torch.max()方法

    一.前言 这个方法跟上一篇文章的torch.max()方法非常类似,只不过一个是求最大值,一个是求平均值.在某些情况下,甚至可以代替下采样中的最大池化和平均池化,所以说,这两个方法的用处还是蛮大的. ...

  9. pytorch 之 torch.max() 和 torch.min() 记录

    两个函数用法相同,此处就介绍max函数. 1.torch.max(data),不指定维度,返回data的最大值. 2.torch.max(data,dim),返回data中指定维度的最大值. 3.to ...

  10. torch.max()函数==》返回该维度的最大值以及该维度最大值对应的索引

    今天在学习TTSR的过程总遇到了一行代码,我发现max()函数竟然可以返回两个值,于是我决定重新学习一下这个函数 R_lv3_star, R_lv3_star_arg = torch.max(R_lv ...

最新文章

  1. 使用photoshop 10.0制作符合社保要求的照片
  2. wxWidgets:wxApp概览
  3. java gui 组件_Java GUI4:深入了解GUI组件
  4. php 备份数据库(生成word,excel,json,xml,sql)
  5. CUDA ---- Hello World From GPU
  6. 关于delphi中多线程采用定时器的做法
  7. DSP之直接存储器访问控制器
  8. 51单片机交通灯(十字路口演示)
  9. 程序员可以培养的第二技能有哪些?
  10. VirtualBox主机与虚拟机互相ping通的方法
  11. codeforces 724F. Uniformly Branched Trees
  12. 关于Win10创意者更新之后蓝屏的修复办法
  13. Rhinoceros mac版(犀牛三维建模软件)中文版
  14. 疯狂springboot终极讲义笔记(二)
  15. linux设置屏蔽海外ip,linux屏蔽海外流量的两种方法
  16. c语言内部收益率,内部收益率 (C++代码)
  17. 单片机中代码生成.a文件
  18. Swift Invalid bitcode version (Producer: '802.0.41.0_0' Reader: '800.0.42.1_0')
  19. Linux kernal
  20. [OpenGL] Hatching 素描画效果

热门文章

  1. GEE-Python遥感大数据分析、管理与可视化实践技术应用
  2. Android判断手机是否在口袋中,距离传感器
  3. L9954LXP_特殊功能,车门模块驱动器
  4. 支付宝支付php开发demo下载地址,tp使用支付宝接口demo
  5. 一个07年毕业研究生的坎坷经历(上)
  6. 小白也能懂的DPDK技术解析
  7. JavaScript 和 Macromedia Flash 之间的通信示例
  8. python算法 之 猜词游戏
  9. 可证明安全的密文策略基于属性加密(Provably Secure Ciphertext Policy ABE)
  10. java循环抓取网页超链接_提取网页中的超链接