问题描述
我试图打印屏幕上ndarray。但是Python始终显示它在科学记数法,这是我不喜欢的。对于一个标量,我们可以使用
I'm trying to print a ndarray on the screen. But python always shows it in scientific notation, which I don't like. For a scalar we can use
>>> print '%2.4f' %(7.47212470e-01)
0.7472
但如何做,像这样的numpy.ndarray:
But how to do that for a numpy.ndarray like this :
[[ 7.47212470e-01 3.71730070e-01 1.16736538e-01 1.22172891e-02]
[ 2.79279640e+00 1.31147152e+00 7.43946656e-02 3.08162255e-02]
[ 6.93657970e+00 3.14008688e+00 1.02851599e-01 3.96611266e-02]
[ 8.49295040e+00 3.94730094e+00 8.99398479e-02 7.60969188e-02]
[ 2.01849250e+01 8.62584092e+00 8.75722302e-02 6.17109672e-02]
[ 2.22570710e+01 1.00291292e+01 1.20918359e-01 1.07250131e-01]
[ 2.82496660e+01 1.27882133e+01 1.08438172e-01 1.58723714e-01]
[ 5.89170270e+01 2.55268510e+01 1.31990966e-01 1.61599514e-01]]
的方法,.astype(浮点)不改变的结果,和.round(4)返回:
The method .astype(float) does not change the result, and .round(4) returns:
[[ 7.47200000e-01 3.71700000e-01 1.16700000e-01 1.22000000e-02]
[ 2.79280000e+00 1.31150000e+00 7.44000000e-02 3.08000000e-02]
[ 6.93660000e+00 3.14010000e+00 1.02900000e-01 3.97000000e-02]
[ 8.49300000e+00 3.94730000e+00 8.99000000e-02 7.61000000e-02]
[ 2.01849000e+01 8.62580000e+00 8.76000000e-02 6.17000000e-02]
[ 2.22571000e+01 1.00291000e+01 1.20900000e-01 1.07300000e-01]
[ 2.82497000e+01 1.27882000e+01 1.08400000e-01 1.58700000e-01]
[ 5.89170000e+01 2.55269000e+01 1.32000000e-01 1.61600000e-01]]
我只是单纯的想了0.7472 0.3717等。
I just simply want the 0.7472 0.3717 etc.
推荐答案
的<$c$c>numpy.set_string_function$c$c>功能可用于更改字符串数组重的presentation。
The numpy.set_string_function
function can be used to change the string representation of arrays.
您也可以使用<$c$c>numpy.set_print_options$c$c>改变默认使用的precision和关闭小数字报告在科学记数法。
You can also use numpy.set_print_options
to change the precision used by default and turn off reporting of small numbers in scientific notation.
从例子 set_print_options
:
>>> np.set_printoptions(precision=4)
>>> print np.array([1.123456789])
[ 1.1235]
这篇关于如何强制,而不是正常的方式科学记数法一ndarray节目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!