python torch.argmax()

语法一:

torch.argmax(input) → LongTensor

Returns the indices of the maximum value of all elements in the input tensor. # 返回输入张量中所有元素的最大值的索引。

参数:
input (Tensor) – the input tensor
例子:
>>> a = torch.randn(3,3)
>>> a
tensor([[-0.0368,  0.0057, -1.5687], [-0.2456,  0.0145, -0.4154], [ 1.0114, -0.4180, -0.5612]])
>>> print(torch.argmax(a))
tensor(6)  # 从0开始计数,从左往右,从上往下
>>>

语法一:

torch.argmax(input, dim, keepdim=False) → LongTensor
参数:
  • input (Tensor) – the input tensor #输入张量

  • dim (int) – the dimension to reduce. If None, the argmax of the flattened input is returned. # 缩小尺寸。如果为None,则返回平坦输入的argmax。

  • keepdim (bool) – whether the output tensors have dim retained or not. Ignored if dim=None.

例子:
>>> import torch
>>> b = torch.randn(4,4)
>>> print(b)
tensor([[-1.5364,  1.6827, -0.0245, -0.1265], [ 0.6040, -0.8682,  0.3914,  0.5424], [-0.6569,  1.2815,  0.3952,  0.6946], [-1.1316,  0.7783,  1.2647, -0.4944]])
>>> print(torch.argmax(b,dim =0))  #竖着比较,找最大
tensor([1, 0, 3, 2])
>>> print(torch.argmax(b,dim =1))  #横着比较,找最大
tensor([1, 0, 1, 2])
更复杂一些的例子:
>>> c= torch.randn(2,3,4)
>>> print(c)
tensor([[[ 0.1911, -1.3272, -0.1704, -1.0493],[ 1.0991, -0.4143, -0.3800, -0.4657],[-0.3569, -0.6414,  1.3495, -0.0230]],[[-2.1686, -1.1714, -0.3639,  0.5945],[-0.4642,  0.8249, -0.0173,  0.1934],[-0.1629,  1.2108,  1.6179, -0.2537]]])
>>> print(torch.argmax(c,dim=0))
tensor([[0, 1, 0, 1],[0, 1, 1, 1],[1, 1, 1, 0]])
>>> print(torch.argmax(c,dim=1))
tensor([[1, 1, 2, 2],[2, 2, 2, 0]])
>>> print(torch.argmax(c,dim=2))
tensor([[0, 0, 2],[3, 1, 2]])

python torch.argmax()相关推荐

  1. torch.argmax()函数

    argmax函数:torch.argmax(input, dim=None, keepdim=False) 返回指定维度最大值的序号,dim给定的定义是:the demention to reduce ...

  2. python torch exp_Python torch.diag方法代码示例

    本文整理汇总了Python中torch.diag方法的典型用法代码示例.如果您正苦于以下问题:Python torch.diag方法的具体用法?Python torch.diag怎么用?Python ...

  3. 【Pytorch】torch.argmax 函数详解

    文章目录 一.一个参数时的 torch.argmax 函数 1. 介绍 2. 实例 二.多个参数时的 torch.argmax 函数 1. 介绍 2. 实例 实例1:二维矩阵 实例2:三维矩阵 实例3 ...

  4. python torch exp_Python torch.add方法代码示例

    本文整理汇总了Python中torch.add方法的典型用法代码示例.如果您正苦于以下问题:Python torch.add方法的具体用法?Python torch.add怎么用?Python tor ...

  5. Python torch 模块,randperm() 实例源码

    参考Python torch 模块,randperm() 实例源码 - 云+社区 - 腾讯云 torch.randperm(n, *, out=None, dtype=torch.int64, lay ...

  6. Pytorch中torch.argmax()函数解析

    一. torch.argmax()函数解析 1. 官网链接 torch.argmax(),如下图所示: 2. torch.argmax(input)函数解析 torch.argmax(input) → ...

  7. 【torch.argmax与torch.max详解】

    Pytorch常用函数 一.torch.max 1.调用方式 2.相关介绍 3.代码实例及图示理解 二.torch.argmax 1.调用方式 2.相关介绍 3.代码实例及图示理解 三.torch.m ...

  8. torch.argmax方法详解

    torch.argmax方法详解 torch.argmax(x, dim),其中x为张量,dim控制比较的维度,返回最大值的索引. 1.当dim=0时 import torch x = torch.r ...

  9. torch.argmax函数说明

    torch.argmax()函数 argmax函数:torch.argmax(input, dim=None, keepdim=False)返回指定维度最大值的序号,dim给定的定义是:the dem ...

最新文章

  1. nginx upstream 调度策略
  2. WinAPI: SetWindowPos - 改变窗口的位置与状态
  3. 使用pngquant来压缩png资源缩小apk
  4. 关于linux系统下文件压缩归档操作命令略提
  5. vue生命周期(列表详解)
  6. ubuntu下命令安装与卸载软件方法
  7. css 背景图怎么设置自动填充满_CSS属性设置 -- 背景样式
  8. java类加public和不加public
  9. Linux的JVM可以从SUN网站上下载
  10. 排除jar_通过IDEA快速定位和排除依赖冲突
  11. html内嵌样式字体,html-通过内联C加载外部字体
  12. 程序员之道——编程也是一门艺术
  13. 平面2R机器人的运动学/动力学建模实例
  14. AspxGridView 排序分组刷新DetailRow的问题
  15. 【Visual Studio 2013中文语言包安装】
  16. 索尼手机的摄像功能怎么样?
  17. keyshot渲染图文教程_keyshot基础图文教程,手把手教你用keyshot制作动画效果
  18. 解析几何----双曲线左支极坐标方程
  19. 全网最细------爬取4k高清大图
  20. CSDN下载频道2013下半年超人气精华资源汇总

热门文章

  1. POE交换机分类有哪些?4口/8口/16口/24口千兆POE交换机有哪些选择?
  2. 魅族mx5android os耗电,魅族mx5运行系统优化
  3. 测试你的大脑思维类型是“左脑型”还是“右脑型”
  4. 【Linux命令-shell】中断退出:基本语法、机选双色球
  5. 基于VC++的MFC框架实现的飞机大战小游戏
  6. 一次详尽的问题定位记录:CPU使用率低负载高的排查过程
  7. c语言if判断大于小于的写法注意
  8. MySQL高级—尚硅谷—周阳—2018-03-28
  9. Mysql 实现连乘法
  10. 新松机器人刻蚀机_新松机器人为何投资韩国半导体与面板设备企业 ?