# Understand torch.scatter_()

# 1. Official Documentation

First, note that scatter_() is an inplace function, meaning that it will change the value of input tensor.

The official document `scatter_`

(*dim*, *index*, *src*) → *Tensor* tells us that parameters include the dim, index tensor, and the source tensor. *dim *specifies where the index tensor is functioning, and we will keep the other dimensions unchanged. And as the function name suggests, the goal is to scatter values in the source tensor to the input tensor *self*. What we are going to do is to loop through the values in the…