Is there a filter similar to ndimage
's generic_filter that supports vector output? I did not manage to make scipy.ndimage.filters.generic_filter
return more than a scalar. Uncomment the line in the code below to get the error: TypeError: only length-1 arrays can be converted to Python scalars
.
I'm looking for a generic filter that process 2D or 3D arrays and returns a vector at each point. Thus the output would have one added dimension. For the example below I'd expect something like this:
m.shape # (10,10)
res.shape # (10,10,2)
Example Code
import numpy as np
from scipy import ndimagea = np.ones((10, 10)) * np.arange(10)footprint = np.array([[1,1,1],[1,0,1],[1,1,1]])def myfunc(x):r = sum(x)#r = np.array([1,1]) # uncomment thisreturn rres = ndimage.generic_filter(a, myfunc, footprint=footprint)