There's a Cython implementation (the .pyx file). The Cython code is compiled to C code (then that C code is compiled).
(2, 3, 4)
(2, 3)
That is - the suffixes do not agree (4 != 3 and 3 != 2) and NumPy raises an error. (2, 3, 4)
(2, 3)
and the addition gives the expected result. (a.T + b.T).T np.sort(a)[-5:]
instead of using argsort() and then using fancy indexing. Better yet, use np.partition(a, kth=-5)[-5:]
which scales linearly with the size of the array. (arr[:, None] == np.unique(arr)).view(np.int8)
In general, `for` loops over NumPy arrays should be avoided where at all possible.