2015-02-11 21 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