For question 48 it might be simpler to just write
np.sort(a)[-5:]
np.partition(a, kth=-5)[-5:]
Also, the one-hot encoding puzzle (51) would be more efficiently solved using
(arr[:, None] == np.unique(arr)).view(np.int8)
For question 48 it might be simpler to just write
instead of using argsort() and then using fancy indexing. Better yet, use which scales linearly with the size of the array.Also, the one-hot encoding puzzle (51) would be more efficiently solved using
In general, `for` loops over NumPy arrays should be avoided where at all possible.