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

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

问题描述

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

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

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

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

好:

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

不好:

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

推荐答案

在 IPython 中你可以使用

In IPython you can use

%precision %.4g

这将打印绝对值小于等于的浮点值1e-4 或 >= 1e4 以科学记数法表示.

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

您可以在 IPython API 文档.有关字符串格式选项,请查看 Python 文档

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天全站免登陆