I am trying to vectorize the following:
n = torch.zeros_like(x)
for i in range(x.shape[0]):
for j in range(x.shape[1]):
for k in range(x.shape[2]):
n[i, j, k] = p[i, x[i, j, k], j, k]
I tried doing something like
n = p[:, x, ...]
but I just get an error that I ran out of memory, which isn't very helpful. I think the problem with this is that instead of getting the value of x at the correct index it is trying to index the entirety of x, but I am not sure how I would go about fixing that if that is the problem.