It’s great.
I have tried to change the index matrix I to a new matrix with size (B*N,3) including the batch index.
And this code works:
x[I[:,0], I[:,1], I[:2]] = S

However, your implementation is faster than mine.
And I have another question. If some indexes are repeating in I, which value in S would replace the value in x?  Is the latter one in I?
PS: This is the first time I post the problem on the forum. I’m sorry for my misoperation. Could you please delete another question? Thanks.