使科学计数法从numpy数组可读 [英] Making scientific notation readable from a numpy array

查看:629
本文介绍了使科学计数法从numpy数组可读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何转换像这样的数组:

How do I convert an array like:

array([ -9.8737e+13, -9.8737e+13, -1.1265e+14, 1.5743e-01, 1.1265e+14, 9.8737e+13, 9.8737e+13])

array([ -9.8737e+13, -9.8737e+13, -1.1265e+14, 1.5743e-01, 1.1265e+14, 9.8737e+13, 9.8737e+13])

转换成numpypython的可读形式?

谢谢!

克里斯

推荐答案

您的数组包含大数值和小数值.很难以一种可读的方式呈现两者.如果您使用科学记数法,则可以紧凑的形式显示数字,但是很难一眼就看出哪些数字大而小.

Your array contains both large and small values. It's hard to present both in a readable way. If you use scientific notation the numbers can be shown in a compact form, but it's hard to tell at a glance which numbers are large and which are small.

或者,您可以显示浮点数而无需科学记数法,例如,如下所示:

Alternatively, you could display the floats without scientific notation, for example, like this:

In [132]: np.set_printoptions(formatter={'float_kind':'{:25f}'.format})

In [133]: x
Out[133]: 
array([   -98737000000000.000000,    -98737000000000.000000,
         -112650000000000.000000,                  0.157430,
          112650000000000.000000,     98737000000000.000000,
           98737000000000.000000])

这可以轻松地区分大号和小号,但是现在眼睛注视着太多的零.

which makes it easy to distinguish the large from the small, but now the eyes boggle looking at too many zeros.

过一会儿,您可能想回到NumPy的默认格式,可以通过不带参数调用np.set_printoptions()来实现.

After a while, you may want to go back to NumPy's default format, which you can do by calling np.set_printoptions() without arguments.

In [134]: np.set_printoptions()

In [135]: x
Out[135]: 
array([ -9.8737e+13,  -9.8737e+13,  -1.1265e+14,   1.5743e-01,
         1.1265e+14,   9.8737e+13,   9.8737e+13])

在任何情况下,以上内容都向您展示了如何配置NumPy以任意方式显示浮点数(或其他类型).有关所有可用选项的更多信息,请参见文档.

Whatever the case, the above shows you how you can configure NumPy to display floats (or other types) any way you wish. See the docs for more on all the available options.

这篇关于使科学计数法从numpy数组可读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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