How to translate this numpy to tensorflow js

Struggling a lot to understand what would be the equivalent of this in tensorflow js:

outputs[..., :2] = (outputs[..., :2] + grids)

help please

Did you try slicing (using “tf.slice”) the tensor to get the first two elements along the last axis, then adding (using “tf.add” method) the “grids” constant to the slice, then finally updating the original tensor using tf.scatterNDUpdate?

1 Like

I have not seen tf.scatter... in tfjs? But I will check. So far what I did was slicing or gathering and then concatenating back, which is terrible…