Say, I have a 2D numpy array consists of 20 elements, for example:
arr = np.array([[1, 2, 15, 7],[9, 11, 17, 19],[5, 7, 5, 8],[19, 4, 1, 45],[10, 7, 14, 8]])
and an additional array:
to_zero = np.array([0, 2, 1, 3, 2])
now, for each row i I would like to make the last to_zero[i] elements equal to zero, so eventually we will get the following result:
res = np.array([[1, 2, 15, 7],[9, 11, 0, 0],[5, 7, 5, 0],[19, 0, 0, 0],[10, 7, 0, 0]])
I would like to do this operation on a very big array. Is there any way to do this operation vectorized, with no loops, and no auxiliary arrays?