我在numpy中使用中值函数时遇到问题。用于在以前的计算机上运行的代码,但是当我尝试在我的新计算机上运行它时,我得到错误"无法使用灵活类型执行reduce#34;。为了尝试修复此问题,我尝试使用map()函数来确保我的列表是一个浮点并收到此错误消息:无法将字符串转换为浮点数:。
在调试方面做了一些尝试,似乎我的问题在于我在输入文件中拆分行。这些行的形式为:2456893.248202,4.490,我想拆分","。但是,当我打印出该行第二列的列表时,我得到了 4 。 4 9 0
所以似乎在某种程度上分裂每个角色或者某些东西虽然我不确定如何。相关的代码部分如下,我感谢任何想法或想法,并提前感谢。
def curve_split(fn):
with open(fn) as f:
for line in f:
line = line.strip()
time,lc = line.split(",")
#debugging stuff
g=open('test.txt','w')
l1=map(lambda x:x+'\n',lc)
g.writelines(l1)
g.close()
#end debugging stuff
return time,lc
if __name__ == '__main__':
# place where I keep the lightcurve files from the image subtraction
dirname = '/home/kuehn/m4/kepler/subtraction/detrending'
files = glob.glob(dirname + '/*lc')
print(len(files))
# in order to create our lightcurve array, we need to know
# the length of one of our lightcurve files
lc0 = curve_split(files[0])
lcarr = np.zeros([len(files),len(lc0)])
# loop through every file
for i,fn in enumerate(files):
time,lc = curve_split(fn)
lc = map(float, lc)
# debugging
print(fn[5:58])
print(lc)
print(time)
# end debugging
lcm = lc/np.median(float(lc))
#lcm = ((lc[qual0]-np.median(lc[qual0]))/
# np.median(lc[qual0]))
lcarr[i] = lcm
print(fn,i,len(files))