2015-02-11 75 views
1

我试图摆脱这种格式,使这个文件在另一个软件中可读。摆脱阵列数组中的格式e + xx,Python

import numpy as np 

test=[5.1056e+02, 6.89752e+05, 4.5987126464655e+03] 
np.round(test,6) 
print(test) 

test2=[[5.1056e+02, 6.89752e+05, 4.5987126464655e+03],[5.1056e+02, 6.89752e+05, 4.5987126464655e+03]] 
test2=np.array(test2) 
np.round(test2,6) 
print(test2) 

第1次印刷给我:

[510.56, 689752.0, 4598.7126464655] 

第二打印给我:

[[ 5.10560000e+02 6.89752000e+05 4.59871265e+03] 
[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]] 

现在的第一个结果将是罚款由我,但我的数据看起来像TEST2。但我仍然不明白np.round的第二个参数是什么,因为它应该限制小数位数,但我仍然得到4598.7126464655。 但至少我会得到一个可用的格式。

如何在test2这样的工作上做这项工作? 我尝试这样做:

for i in range(np.shape(test2)[0]): 
    np.round(test2[i]) 

print(test2) 

仍然给我:

[[ 5.10560000e+02 6.89752000e+05 4.59871265e+03] 
[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]] 
+0

'np.round(test,6)'不会修改'test'对象本身。它返回一个新的对象。所以你必须做'test = np.round(test,6)' – eumiro 2015-02-11 09:26:29

回答

-1

4.59871265e+03 is actually equivalent to 4598.71265

>>> 4.59871265e+03 == 4598.71265 
True 

所以你的舍入工作得很好。 You need to set

np.set_printoptions(suppress=True) 

打印前。

+1

不。看起来像,但它不。 OP没有分配回合的回报值。 – Carsten 2015-02-11 09:31:35

+0

除了我做出这些改变之后,它并没有解决我科学格式e + xx的问题 – Pauline1006 2015-02-11 09:37:57