I require a functionality that comes close to TensorFlows scatter_nd function, I guess.

Let’s assume that I have an m-x-n matrix A and four row vectors N, S (of size n) and E, E (of size m). I need to create a new matrix B with the four vectors replacing the first/last row/column, e.g.

The vectors are such that N1=W1, Wm=S1, … so it does not matter whether N1 or W1 it put at B1,1, etc.

The above ist just an example, I need the same for 3 and 4 dimensional tensors, then replacing the “boundaries” of the tensors by matrices and 3-d tensors, respectively.

thanks. Two questions on this: How do I realise this in C++ (Tensor Indexing API — PyTorch main documentation) and does the above work when I need to compute gradients of the resulting tensor?