是否有类似于支持向量输出ndimage
的generic_filter的过滤器?我没有设法使scipy.ndimage.filters.generic_filter
return 超过一个标量。取消注释下面代码中的行以获取错误:TypeError: only length-1 arrays can be converted to Python scalars
.
我正在寻找一个处理 2D 或 3D 数组并在每个点返回一个向量的通用过滤器。因此,输出将增加一个维度。对于下面的示例,我希望是这样的:
m.shape # (10,10)
res.shape # (10,10,2)
示例代码
import numpy as np
from scipy import ndimage
a = 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 this
return r
res = ndimage.generic_filter(a, myfunc, footprint=footprint)