## how numpy partition work

Question

I am trying to figure out how `np.partition`

function works.
For example, consider

`arr = np.array([ 5, 4, 1, 0, -1, -3, -4, 0])`

If I call `np.partition(arr, kth=2)`

, I got

`np.array([-4, -3, -1, 0, 1, 4, 5, 0])`

I expect that after partition array will splits into elements less one, one and elements greater one. But the second zero placed on the last array position, which isn't its right place after partition.

Show source

## Answers ( 1 )

The documentation is quite clear:

In the example you give, you have selected 2th element of the sorted list (starting from zero), which is -1, and it seems to be in the right position if the array was sorted.