NumPy. Apply_along_axis (func, axis, arr, *args, **kwargs):
Required Parameters: Func,axis,arr. Where Func is our custom function, arr in function func is an array, and the main function of the function is to transform each element in the array to get the result of the target.
where axis represents the function func for the axis of an array of arr functions.
Optional parameters:*args, **kwargs. Are the additional parameters of the Func () function.
return value: NumPy. The Apply_along_axis () function returns an array based on the Func () function and the axis operation of the dimension .
Instance:
Def My_func (a):
Return (A[0] + a[-1]) * 0.5
B=np.array ([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
Np.apply_along_axis (My_func, 0, B)
Output: Array ([5., 6., 7., 8.])
Np.apply_along_axis (My_func, 1, b)
Output: Array ([2.5, 6.5, 10.5])
NumPy English Interpretation document
The use of the Numpy.apply_along_axis () function in Python