将numpy数组保存为CSV而无需科学记数法

import numpy as np

 A = ['33.33', '33.33', '33.33', '33.37']

 NA = np.asarray(A)
 NA = NA.astype(float)
 AVG = np.mean(NA, axis=0)
 MN = np.min(NA, axis=0)
 MX = np.max(NA, axis=0)

 print AVG, MN, MX

np.savetxt('datasave.csv', (AVG,MN,MX), delimiter=',')

此时出现的csv文件内数字以科学计数法形式存在。

 

In [153]: print(AVG, MN, MX)
33.34 33.33 33.37

默认写:

In [154]: np.savetxt('test.txt',(AVG, MN, MX), delimiter=',')
In [155]: cat test.txt
3.333999999999999631e+01
3.332999999999999829e+01
3.336999999999999744e+01

使用自定义fmt

进行书写

In [156]: np.savetxt('test.txt',(AVG, MN, MX), delimiter=',', fmt='%f')
In [157]: cat test.txt
33.340000
33.330000
33.370000

或者如果你想在一行上使用值,那么将它设为2d数组(或者使用extra []),这样它每行写一行:

In [160]: np.savetxt('test.txt',[[AVG, MN, MX]], delimiter=',', fmt='%f')
In [161]: cat test.txt
33.340000,33.330000,33.370000

您可以尝试其他参数。

你可能感兴趣的:(将numpy数组保存为CSV而无需科学记数法)