# Increasing the values for specific indices in a tensor

I want to increase specific indices in a tensor by 10%.
I have a tensor

``````x = torch.randint(-2,2,[4,3])

tensor([[-2,  0,  1],
[-2,  1, -2],
[ 0,  0, -1],
[ 0, -1,  1]])
``````

and the following indices

``````indices = torch.tensor([[0,0,1],[2,1,1]])
``````

I want to increase the values by 10% on the indices above, so that I get the following tensor

``````tensor([[-2,  0,  1.1],
[-2,  1.1, -2],
[ 0,  0, -1],
[ 0, -1,  1]])
``````

How can I achieve that?

Hi,

I guess you can do something like this no?
`x[indices, indices] *= 1.1`

HI @albanD thank you for the response.
I tried your solution but I lose the full matrix, ang get only the selected vector

``````x[indices, indices]

>> tensor([ 1, -2, -1])
``````

Also, multiplying by negative numbers by 1.1 will reduce them and instead of increasing them
so I guess I need a calculation similar to

``````x + x.abs() * 0.1
``````

I just don’t know how to apply it only on the specific indices.

Ho in that case you can do:

``````vals = x[indices, indices]
updated_vals = vals + vals.abs() * 1.1
x[indices, indices] = vals
``````

Thank you @albanD, just what I was looking for