错误'bool'对象没有属性'any'

时间:2014-02-13 03:49:12

标签: python-2.7 scipy

我写了一个脚本来做插值

import scipy.interpolate
import csv
inputfile1 = 'test.csv'
outputfile = 'Day1_out.csv'
distance_list = []
EC_list = []
new_dist_list=[]
outfile = open(outputfile,'w')
outfile.write('Distance,EC\n')

with open (inputfile1,'rb') as csvfile:
    f1 = csv.reader(csvfile,delimiter=',')
    next(f1) #skip header line
    for row in f1:
        dist = row[12]
        EC=row[13]
        distance_list.append(dist)
        EC_list.append(EC)
y_interp = scipy.interpolate.interp1d(distance_list,EC_list)
new_dist = 561.7
end = 560.2
while new_dist>end:
    new_dist_list.append(dist)
    new_dist=new_dist-0.2
for distance in new_dist_list:
    EC=y_interp(distance)
    outfile.write(str(distance)+','+str(EC)+'\n')
outfile.close()

当我运行脚本时,它给了我错误消息 回溯(最近一次调用最后一次):

  File "D:\14046\Scripts\interpolation_RoR.py", line 41, in <module>
    EC=y_interp(distance)

  File "C:\Python27\lib\site-packages\scipy\interpolate\polyint.py", line 54, in __call__
    y = self._evaluate(x)

  File "C:\Python27\lib\site-packages\scipy\interpolate\interpolate.py", line 448, in _evaluate
    out_of_bounds = self._check_bounds(x_new)

  File "C:\Python27\lib\site-packages\scipy\interpolate\interpolate.py", line 474, in _check_bounds
    if self.bounds_error and below_bounds.any():

AttributeError: 'bool' object has no attribute 'any'

任何人都知道我哪里有错误?

BTW,输入文件具有这些距离和EC

的值

距离,EC

561.8,450

561.78,446

561.7,444

561.2,440

561.02,438

560.5,437

560.1,435

谢谢,

1 个答案:

答案 0 :(得分:1)

我们在此处收到相同的错误消息。我认为这不一定是您的代码的问题。

在我们的情况下,切换到SciPy version 0.15.0而不是0.13.x可以解决问题。

所以看起来当前版本的SciPy接受更广泛的输入值。