# Indexing a indexed tensor

Hello guys,

i am trying to access an indexed tensor in the following way:

``````
x = tr.tensor([True]*10, dtype=tr.bool)
y = tr.tensor([True]*10, dtype=tr.bool)

x[3]    = False
y[~x]   = False # works fine
x[y][3] = False # does not change the tensor x, but why?
``````

Obviously the second indexing `x[y][3]` creates a copy of the tensor x[y], which is a little bit weird but ok. My question is how i can access the original tensor x?

``````x = tr.tensor([True]*10, dtype=tr.bool)
y = tr.tensor([True]*10, dtype=tr.bool)

x[3]    = False
y[~x]   = False # works fine
temp = x[y]
temp[3] = False
x[y] = temp # works fine
``````

But c’mon is there any nice solution? Actually the tensors contain more than 1000 bools and i have to do these operations very often in a for loop so i do not want to copy them.

You could try to replace the sequential indexing with

``````x[y.nonzero()[3]] = False
``````

which should yield the desired result based on your example.

And again you nailed it. Thanks a lot.