概述
例如,如果A [0]总是包含当前元素(似乎不是这种情况),则以下内容可能会找到局部最大值
def local_max_f(A) : return A[0] == A.max() img = np.random.rand(100).reshape(10,10) ndimage.generic_filter( img,local_max_f,size=3 )
docs instead provide a neat example(适用于您的情况)用于确定过滤器中的当前位置,使用类来维持迭代之间的某些状态.这总是先遍历最后一个维度;所有你应该做的就是用你的过滤函数实际需要做的事情来替换结果行,在你的情况下,这将类似于result = self._array [self.coordinates] == buffer.max().
a = arange(12).reshape(3,4) class fnc_class: def __init__(self,_array): # store the shape: self.shape = _array.shape self._array = _array # initialize the coordinates: self.coordinates = [0] * len(self.shape) def filter(self,buffer): result = self._array[tuple(self.coordinates)] == buffer.max() print self.coordinates # calculate the next coordinates: axes = range(len(self.shape)) axes.reverse() for jj in axes: if self.coordinates[jj] < self.shape[jj] - 1: self.coordinates[jj] += 1 break else: self.coordinates[jj] = 0 return result fnc = fnc_class(a) generic_filter(a,fnc.filter,footprint = [[1,0],[0,1]])
总结
以上是编程之家为你收集整理的python – 在scipy.ndimage.filters.generic_filter中获取当前元素全部内容,希望文章能够帮你解决python – 在scipy.ndimage.filters.generic_filter中获取当前元素所遇到的程序开发问题。
如果您也喜欢它,动动您的小指点个赞吧