I have 2d numpy array of size ~70k * 10k. I want to replace all values with zero which are smaller than the "N" largest element in every row. For example:
arr = np.array([[1, 0, 6, 5, 2, 5],
[7, 5, 2, 6, 7, 3],
[3, 5, 1, 5, 6, 4]])
For N = 3
the result should be:
result = np.array([[0, 0, 6, 5, 0, 5], # 3 largest in row: 6, 5, 5
[7, 0, 0, 6, 7, 0],
[0, 5, 0, 5, 6, 0]])
The positions of numbers that were not replaced and the shape of the array should stay the same.