我在问,因为我遇到了一些非常奇怪的事情。从脚本中调用时,以下方法抛出异常:
def gaussian_blur(self, in_array, size):
# expand in_array to fit edge of kernel
padded_array = np.pad(in_array, (10,), 'reflect')
# build kernel
x, y = np.mgrid[-size:size + 1, -size:size + 1]
g = np.exp(-(x**2 / float(size) + y**2 / float(size)))
g = (g / g.sum()).astype(in_array.dtype)
# do the Gaussian blur
return fftconvolve(padded_array, g, mode='valid')
Traceback (most recent call last):
File "raster_tools/smooth.py", line 130, in <module>
blurred = ri.gaussian_blur(my_array, 10)
File "raster_tools/smooth.py", line 80, in gaussian_blur
padded_array = np.pad(in_array, (10,), 'reflect')
File "/home/.virtualenvs/geo/local/lib/python2.7/site-packages/numpy/lib/arraypad.py", line 1358, in pad
kwargs)
File "/home/.virtualenvs/geo/local/lib/python2.7/site-packages/numpy/lib/shape_base.py", line 91, in apply_along_axis
res = func1d(arr[tuple(i.tolist())], *args, **kwargs)
TypeError: 'unicode' object is not callable
当我使用ipdb设置断点然后调用
padded_array = np.pad(in_array, (10,), 'reflect')
(以及函数中的所有其他代码行)以及错误都不会发生。当在虚拟环境中调用python脚本时,我可以想象ipdb
正在使用不同的解释器。即使在虚拟环境之外运行代码也会产生相同的行为。