numpy-100
numpy-100 copied to clipboard
I have a better way to solve exercise 89
I think
print(np.sort(Z)[-n:])
or
Z.sort()
print(Z[-n:])
would be better than
https://github.com/rougier/numpy-100/blob/916e1ecf9544719b49ece6fc135b089988b33058/100_Numpy_exercises_with_hints_with_solutions.md#L1084
because the first solution is simpler, and if it's ok to modify the array in place, the second solution is faster and uses less space.
It is written that argsort is the slow solution and Z[np.argpartition(-Z,n)[:n]] is faster because of partial ordering.
I read that, but either of the solutions I wrote would be a better slow solution, right?