【发布时间】:2015-04-30 17:31:22
【问题描述】:
有没有类似ndimage的generic_filter的过滤器支持向量输出?我没有设法让scipy.ndimage.filters.generic_filter 返回超过一个标量。取消注释下面代码中的行以获取错误: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)
【问题讨论】:
标签: python image-processing numpy scipy ndimage