zoukankan      html  css  js  c++  java
  • pytorch 的max函数

    torch.max(input) → Tensor

    返回输入tensor中所有元素的最大值

    a = torch.randn(1, 3)
    >>0.4729 -0.2266 -0.2085

    torch.max(a)
    >>0.4729
     

    torch.max(input, dim, keepdim=False, out=None) -> (Tensor, LongTensor)

    按维度dim 返回最大值

    torch.max)(a,0) 返回每一列中最大值的那个元素,且返回索引(返回最大元素在这一列的行索引)

    a = torch.randn(3,3)
    >>
    0.2252 -0.0901 0.5663
    -0.4694 0.8073 1.3596
    0.1073 -0.7757 -0.8649

    torch.max(a,0)
    >>
    (
    0.2252
    0.8073
    1.3596
    [torch.FloatTensor of size 3]
    ,
    0
    1
    1
    [torch.LongTensor of size 3]
    )
    torch.max(a,1) 返回每一行中最大值的那个元素,且返回其索引(返回最大元素在这一行的列索引)

    a = torch.randn(3,3)
    >>
    0.2252 -0.0901 0.5663
    -0.4694 0.8073 1.3596
    0.1073 -0.7757 -0.8649

    torch.max(a,1)
    >>
    (
    0.5663
    1.3596
    0.1073
    [torch.FloatTensor of size 3]
    ,
    2
    2
    0
    [torch.LongTensor of size 3]
    )
    torch.max()[0], 只返回最大值的每个数

    troch.max()[1], 只返回最大值的每个索引

    torch.max()[1].data 只返回variable中的数据部分(去掉Variable containing:)

    torch.max()[1].data.numpy() 把数据转化成numpy ndarry

    torch.max()[1].data.numpy().squeeze() 把数据条目中维度为1 的删除掉

    torch.max(tensor1,tensor2) element-wise 比较tensor1 和tensor2 中的元素,返回较大的那个值
    ————————————————
    版权声明:本文为CSDN博主「摇摆的果冻」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/Z_lbj/article/details/79766690

  • 相关阅读:
    fatal error LNK1123: failure during conversion to COFF: file invalid or corr
    BEGIN_SINK_MAP(CMainDlg) SINK_ENTRY(IDC_EXPLORER1, ..。响应不到的
    第三周项目3-程序的多文件组织
    第三周项目2-三角形类(二)
    第三周项目1-三角形类(一)
    第三周课后实践-阅读程序
    第二周项目4-图书馆的书
    第二周项目3-时间类
    第二周项目2-长方柱类
    第二周项目1-旱冰场造价
  • 原文地址:https://www.cnblogs.com/loubin/p/12775576.html
Copyright © 2011-2022 走看看