This function should accept 1-D arrays. It is applied to 1-D
slices of arr along the specified axis.
axis : integer
Axis along which arr is sliced.
arr : ndarray (Ni…, M, Nk…)
Input array.
args : any
Additional arguments to func1d.
kwargs : any
Additional named arguments to func1d.
Returns:
out : ndarray (Ni…, Nj…, Nk…)
The output array. The shape of out is identical to the shape of
arr, except along the axis dimension. This axis is removed, and
replaced with new dimensions equal to the shape of the return value
of func1d. So if func1d returns a scalar out will have one
fewer dimensions than arr.
Examples
>>> importnumpyasnp>>> defmy_func(a):... """Average first and last element of a 1-D array"""... return(a[0]+a[-1])*0.5>>> b=np.array([[1,2,3],[4,5,6],[7,8,9]])>>> np.apply_along_axis(my_func,0,b)array([4., 5., 6.])>>> np.apply_along_axis(my_func,1,b)array([2., 5., 8.])
For a function that returns a 1D array, the number of dimensions in
outarr is the same as arr.