【问题标题】:Prevent Jupyter from switching between normal mathematical notation and scientific notation防止 Jupyter 在普通数学记数法和科学记数法之间切换
【发布时间】:2020-02-19 00:27:45
【问题描述】:

我想问一个关于在 Jupyter notebook 中关闭数字科学记数法的问题。

我有一个名为 my_array 的数组,它在调用时显示以下内容:

my_array
---------
array([[1.63276953e+02, 1.41858314e-01],
   [1.64042353e+02, 5.13131094e-01]])

我想以正常形式显示它,即

array([[163.27... , 0.141... ],
   [164.04... , 0.513...]])

我正在使用pylab(也称为matplotlib)和numpy,并已将其导入:

%pylab inline
import numpy as np

我尝试使用此处在另一个问题中给出的这种方法来解决此解决方案,但这涉及 panda 而不是上述任何一个模块。

如何在此处隐藏科学记数法?

【问题讨论】:

    标签: python numpy jupyter


    【解决方案1】:

    这是numpy 打印问题:

    In [544]: with np.printoptions(suppress=True): 
         ...:     np.array([[1.63276953e+02, 1.41858314e-01], 
         ...:    [1.64042353e+02, 5.13131094e-01]]) 
         ...:                                                                                      
    In [545]: with np.printoptions(suppress=True): 
         ...:    print( np.array([[1.63276953e+02, 1.41858314e-01], 
         ...:    [1.64042353e+02, 5.13131094e-01]])) 
         ...:     
         ...:                                                                                      
    [[163.276953     0.14185831]
     [164.042353     0.51313109]]
    
    In [546]: with np.printoptions(suppress=False): 
         ...:    print( np.array([[1.63276953e+02, 1.41858314e-01], 
         ...:    [1.64042353e+02, 5.13131094e-01]])) 
         ...:     
         ...:                                                                                      
    [[1.63276953e+02 1.41858314e-01]
     [1.64042353e+02 5.13131094e-01]]
    

    np.set_printoptions 可用于更改会话/脚本的此(和其他)选项。

    【讨论】:

      猜你喜欢
      • 2022-10-10
      • 1970-01-01
      • 2016-02-21
      • 1970-01-01
      • 2022-01-19
      相关资源
      最近更新 更多