深入浅出Pytorch函数——torch.max

分类目录:《深入浅出Pytorch函数》总目录

相关文章:

· 深入浅出Pytorch函数------torch.max

· 深入浅出Pytorch函数------torch.maximum


torch.max有三种输入形式,根据其输入形式及参数的不同有下列三种返回形式:

  • torch.max(input):返回输入张量所有元素的最大值。
  • torch.max(input, dim, keepdim=False, *, out=None):返回输入张量给定维度上每行的最大值,并同时返回每个最大值的位置索引。如果keepdim为True,则输出张量的大小与输入张量的大小相同,但尺寸为1的维度dim除外。否则,dim会被挤压(请参见torch.squeeze()),即输出张量比输入少1个维度。
  • torch.max(input, other, *, out=None):参考torch.maximum

语法

复制代码
torch.max(input) -> Tensor
torch.max(input, dim, keepdim=False, *, out=None) -> (values, indices) 
torch.max(input, other, *, out=None) -> Tensor

参数

  • input:`Tensor` 输入张量
  • dim:`int` 待求最大值维度的索引,即返回值中被收缩维度的索引
  • keepdim:`bool` 是否保持输出张量与输入张量的形状一致,默认为False

实例

复制代码
>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.6763,  0.7445, -2.2369]])
>>> torch.max(a)
tensor(0.7445)

>>> a = torch.randn(4, 5)
>>> a
tensor([[ 1.1299, -1.2838, -1.0533, -1.8278,  0.1653],
        [ 0.6461,  0.4583,  1.5229, -1.0642, -1.8352],
        [-0.9679,  1.1227, -0.2506, -0.4781, -0.2027],
        [ 0.2576,  0.7588, -0.1484, -0.0256,  0.7012]])

>>> torch.max(a, 0)
torch.return_types.max(
values=tensor([ 1.1299,  1.1227,  1.5229, -0.0256,  0.7012]),
indices=tensor([0, 2, 1, 3, 3]))

>>> torch.max(a, 1)
torch.return_types.max(
values=tensor([1.1299, 1.5229, 1.1227, 0.7588]),
indices=tensor([0, 2, 1, 1]))
相关推荐
财税数字化几秒前
日韩泰票据与欧美发票混合入账怎么选?开灵科技与海外厂商优劣势对比
大数据·人工智能·科技·ocr·软件选型·票据识别
Axis tech10 分钟前
Xsens&Manus全身数据采集解决方案,用精确数据训练您的具身智能
人工智能·科技·机器人
2601_9556624613 分钟前
1300多种音色怎么挑?不同短视频场景的配音思路
人工智能·音视频
qq_252941316818 分钟前
多模态屋顶损伤与杂物检测数据集 | 屋顶检测 多模态 红外可见光 建筑巡检 目标检测9232期
人工智能·深度学习·yolo·目标检测·计算机视觉·屋顶
java1234_小锋21 分钟前
Arthas 4 宣布正式拥抱 AI
人工智能
TomEval25 分钟前
【测AI】第17篇:大模型评测方法论 —— LLM 怎么测?
人工智能·python·aigc·测试用例
2601_9656196925 分钟前
新闻数据可视化视频:AI自动生成图表动画的完整流程
人工智能·信息可视化·音视频
志尊宝29 分钟前
AI原生前端开发(018):端侧AI性能优化:模型加载、推理加速
人工智能·性能优化·ai-native
renhongxia130 分钟前
RAG检索增强生成:打通大模型与外部知识的通道
大数据·人工智能·算法
jarvisuni33 分钟前
【无标题】
人工智能·ai编程