I am faced with the following problem:
I have a numpy array A of shape (*S, N, N) where S is an arbitrary tuple and N is some positive integer. Another array I of shape (*S, 2) represents indices in A. The values in I are integers in {0, ..., N-1}.
I would like to set
A[i1, ...., ik, I[i1, ..., ik, 0], I[i1, ...., ik, 1]] := 0 (Pseudocode)
for all valid indices i1, ..., ik.
For instance, consider the following example where N=3 and S=(2):
A = np.array([[[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9]],
[[10, 11, 12],
[13, 14, 15],
[16, 17, 18]]])
I = np.array([[0, 2],
[2, 1]])
The desired output in this case would be
np.array([[[ 1, 2, 0],
[ 4, 5, 6],
[ 7, 8, 9]],
[[10, 11, 12],
[13, 14, 15],
[16, 0, 18]]])
Note that the 3 at index (0, 0, 2) (corresponding to the value I[0] being np.array([0, 2])) and the 17 at index (1, 2, 1) (corresponding to the value I[1] being np.array([2, 1])) were changed to 0.
This looks a little like the scatter operation in PyTorch. However, it doesn't exactly match that problem. Additionally, numpy doesn't provide a scatter method. I have worked through numpy's documentation on indexing and a variety of methods to distribute values. Nonetheless, I haven't managed to come up with a clever approach to solve this problem (i.e. one without loops).
I would be grateful for suggestions!

