2015-08-20 11 views
-1

我如何轉換一個這樣的數組:Python的 - 數轉換到指數

[ 76809102.22 38393173.33 -17066.67 -48000000.   0.   0. -28809102.22 -38393173.33 -17066.67] 

以指數?

[ 7.68091022e+07 3.83931733e+07 -1.70666700e+04 -4.80000000e+07 0.00000000e+00 0.00000000e+00 -2.88091022e+07 -3.83931733e+07 -1.70666700e+04] 

我一直在嘗試很多事情,只得到錯誤!

+0

將來,它有助於包括__what__您嘗試過__什麼錯誤___你實際得到,以及一個完整的追溯。 「我一直在嘗試的東西,它不工作」是一個偉大的抱怨,但一個可怕的問題描述,如果你的目標是從陌生人得到幫助。 –

回答

1

如果x是NumPy的數組,那麼你可以使用

np.set_printoptions(formatter={'float': '{: 0.8e}'.format}) 

change the way floats are displayed

import numpy as np 

x = np.array([76809102.22, 38393173.33, -17066.67, -48000000., 0., 0., -28809102.22, 
       -38393173.33, -17066.67]) 
np.set_printoptions(formatter={'float': '{: 0.8e}'.format}) 
print(x) 

產生

[ 7.68091022e+07 3.83931733e+07 -1.70666700e+04 -4.80000000e+07 
    0.00000000e+00 0.00000000e+00 -2.88091022e+07 -3.83931733e+07 
-1.70666700e+04] 
0

使用Ë格式爲代表的十進制數字指數符號:

'{:e}'.format(1.0) 
'1.000000e+00'