【问题标题】:numpy: Print array enforcing scientific notationnumpy:打印数组强制科学记数法
【发布时间】:2021-10-11 11:30:17
【问题描述】:

我需要用科学记数法打印一个 numpy 数组,而不管数组组件的值如何。

据我所知,numpy.format_float_scientific 仅作用于标量,如果应用于向量则返回错误 - 因此,我需要一个替代方案。

谢谢你, 大卫

【问题讨论】:

    标签: python arrays numpy printing scientific-notation


    【解决方案1】:

    我会这样做:

    np.set_printoptions(formatter={'all':np.format_float_scientific})
    print(np.arange(5))
    

    输出:

    [0.e+00 1.e+00 2.e+00 3.e+00 4.e+00]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-26
      • 1970-01-01
      • 2014-03-20
      • 2018-09-13
      • 2017-10-16
      • 2018-11-19
      • 2017-07-30
      相关资源
      最近更新 更多