【问题标题】:Pytorch min and max of tensor [closed]张量的Pytorch最小值和最大值[关闭]
【发布时间】:2021-05-09 21:32:32
【问题描述】:

我有以下 pytorch 张量:

>>> mean_actions
tensor([[-5.7547e-04,  1.4318e-02,  1.9328e-04, -2.5660e-03,  3.5269e-03,
         -1.3797e-02, -6.1871e-04, -2.7425e-03,  1.1661e-03,  1.6873e-03,
          3.9045e-03,  1.8047e-03,  4.8656e-03,  5.7182e-03, -4.8501e-03,
         -5.5913e-03, -4.4574e-03, -3.3154e-03, -4.9826e-03, -1.0071e-02,
         -2.3483e-03, -1.1413e-02, -4.9613e-03, -1.1648e-02,  2.4752e-03,
         -1.9764e-03,  3.1063e-03, -6.3481e-05,  7.6710e-03,  5.7503e-04]])

我从张量中得到以下最小值和最大值:

>>> th.min(mean_actions)
tensor(-0.0138)
>>> th.max(mean_actions)
tensor(0.0143)

但是,我在张量中看不到 -0.01380.0143。我错过了什么?

以下是调试会话的屏幕截图:

【问题讨论】:

    标签: python machine-learning neural-network pytorch


    【解决方案1】:

    两者都存在,它是科学计数法。要摆脱 pytorch 中的科学记数法,请使用 torch.set_printoption()

    >>> th = torch.tensor(([[-5.7547e-04,  1.4318e-02,  1.9328e-04, -2.5660e-03,  3.5269e-03,
    ...          -1.3797e-02, -6.1871e-04, -2.7425e-03,  1.1661e-03,  1.6873e-03,
    ...           3.9045e-03,  1.8047e-03,  4.8656e-03,  5.7182e-03, -4.8501e-03,
    ...          -5.5913e-03, -4.4574e-03, -3.3154e-03, -4.9826e-03, -1.0071e-02,
    ...          -2.3483e-03, -1.1413e-02, -4.9613e-03, -1.1648e-02,  2.4752e-03,
    ...          -1.9764e-03,  3.1063e-03, -6.3481e-05,  7.6710e-03,  5.7503e-04]]))
    >>> th
    tensor([[-5.7547e-04,  1.4318e-02,  1.9328e-04, -2.5660e-03,  3.5269e-03,
             -1.3797e-02, -6.1871e-04, -2.7425e-03,  1.1661e-03,  1.6873e-03,
              3.9045e-03,  1.8047e-03,  4.8656e-03,  5.7182e-03, -4.8501e-03,
             -5.5913e-03, -4.4574e-03, -3.3154e-03, -4.9826e-03, -1.0071e-02,
             -2.3483e-03, -1.1413e-02, -4.9613e-03, -1.1648e-02,  2.4752e-03,
             -1.9764e-03,  3.1063e-03, -6.3481e-05,  7.6710e-03,  5.7503e-04]])
    >>> torch.set_printoptions(sci_mode=False)
    >>> th
    tensor([[    -0.0006,      0.0143,      0.0002,     -0.0026,      0.0035,
                 -0.0138,     -0.0006,     -0.0027,      0.0012,      0.0017,
                  0.0039,      0.0018,      0.0049,      0.0057,     -0.0049,
                 -0.0056,     -0.0045,     -0.0033,     -0.0050,     -0.0101,
                 -0.0023,     -0.0114,     -0.0050,     -0.0116,      0.0025,
                 -0.0020,      0.0031,     -0.0001,      0.0077,      0.0006]])
    

    【讨论】:

      【解决方案2】:

      1.4318e-02 是 0.014318 的科学计数法

      -1.3797e-02 是 -0.013797 的科学记数法

      Wikipedia - E Notation

      【讨论】:

        猜你喜欢
        • 2021-10-17
        • 2021-03-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-09
        • 1970-01-01
        • 2023-04-02
        相关资源
        最近更新 更多