I have come across the numpy.apply_along_axis function in some code. And I don't understand the documentation about it.

This is an example of the documentation:

>>> def new_func(a):
...     """Divide elements of a by 2."""
...     return a * 0.5
>>> b = np.array([[1,2,3], [4,5,6], [7,8,9]])
>>> np.apply_along_axis(new_func, 0, b)
array([[ 0.5,  1. ,  1.5],
       [ 2. ,  2.5,  3. ],
       [ 3.5,  4. ,  4.5]])

As far I as thought I understood the documentation, I would have expected:

array([[ 0.5,  1. ,  1.5],
       [ 4  ,  5  ,  6  ],
       [ 7  ,  8  ,  9  ]])

i.e. having applied the function along the axis [1,2,3] which is axis 0 in [[1,2,3], [4,5,6], [7,8,9]]

Obviously I am wrong. Could you correct me ?

Edit
Report