The use of the Numpy.apply_along_axis () function in Python

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.