设置ipython的默认科学记数法阈值 [英] set ipython's default scientific notation threshold

查看:220
本文介绍了设置ipython的默认科学记数法阈值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何修改python决定以科学记数法打印的点?

例如,我想要一切> 1e4 < 1e-4 以科学记数法打印。

好:

  In [11]:5e20 
Out [11]:5e + 20

坏:

pre $ 在[12]:5e10
出[12]:50000000000.0 $ b $在IPython中,你可以使用
$ b $ / $ p

解决方案

b $ b

 %precision%.4g 

将打印绝对值为< 1e-4或> = 1e4以科学记数法。

有关%precision 命令的详细信息,请参阅 IPython API文档
对于字符串格式化选项,请查看 Python文档


How can I modify the point at which python decides to print in scientific notation?

E.g. I'd like everything > 1e4 or < 1e-4 to be printed in scientific notation.

Good:

In [11]: 5e20
Out[11]: 5e+20

Bad:

In [12]: 5e10
Out[12]: 50000000000.0

解决方案

In IPython you can use

%precision %.4g

this will print floating point values who's absolute value is < 1e-4 or >= 1e4 in scientific notation.

You can find more information about the %precision command in the IPython API Docs. For string formatting options have a look at the Python Docs

这篇关于设置ipython的默认科学记数法阈值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆