我第一次尝试使用 scipy.ndimage.generic_filter1d ,但进展不顺利。这就是我正在尝试的
import numpy as np
from scipy.ndimage import generic_filter1d
def test(x):
return x.sum()
im_cube = np.zeros((100,100,100))
calc = generic_filter1d(im_cube, test, filter_size=5, axis=2)
但我得到这个错误:
TypeError: test() takes 1 positional argument but 2 were given
我正在使用 scipy 1.4.1 我做错了什么?
对于该功能,我也尝试了 np.mean 但后来我得到了这个:
TypeError: only integer scalar arrays can be converted to a scalar index