当我在x数组中使用numpy.astype时,如何将科学记数法转换为原始格式?这是我的代码:
with open ('outfile.csv', 'r') as infile:
reader = csv.reader(infile)
reader_list = list(reader)
reader_array = array(reader_list)
x = reader_array[:,5].astype(np.float)
#original array:
print reader_array[:,5]
#converted to float
print x
#original array:
['-0.00041955436132607246' '-0.00036612800229292086' '0.00022313364860991641' ..., '73.418371245304215' '73.417384428365267' '73.416718169781149']
#converted to float
[ -4.19554361e-04 -3.66128002e-04 2.23133649e-04 ..., 7.34183712e+01 7.34173844e+01 7.34167182e+01]
更具体地说,我想将字符串数组转换为浮点数,但保持与原始数组相同的格式,并对其进行一些分析:
#find row number of max value in column 1: (This piece works fine)
max_index = where(reader_array[:,1] == max(reader_array[:,1]))
#take last element in column 5: (This one is also fine)
total_ = (reader_array[(len(reader_array[:,5])-1),5])
#find row number where element in column 5 is equal to 0.1*total_: (here's the problem!)
0.1_index = where((reader_array[:,5]) == (total_)*0.1)
所以我认为将字符串更改为浮点数但使用与原始数组相同的格式允许将数组成员乘以另一个浮点数(此处为0.1)。
请注意,值(0.1 * total_)可能与第5列中的任何行值不匹配,我必须考虑如何解决。但是如果不能将行与(0.1 *总_)进行比较,我就无法前进。
如果有人可以提示如何处理,我感激不尽。