A question about torch.where

Hey, I have a question about torch.where.

I want to get this:
image[x,y]=p, where x, y, p are lists. For example,

x=[1, 1, 2]

y=[3, 3, 4]

p=[1, 2, 3]

It should be mentioned that image[x][y] may be updated twice, since x[0]=x[1]=1, y[0]=y[1]=3, but p[0]=1, p[1]=2. In this case, image[1][3] should be the minimum, 1.

But torch.where cannot achieve this, and the comparison may be done in parallel, so image[1][3] is not the minimum.
Is there an efficient way to do this? Better use OP of Pytorch. I can update image in a for loop, but it’s too slow, since the len(x) is big.