# Tensors: replacement if condition

Hello,
I’m trying to replace the value of a tensor `x` when the value in `x` and the corresponding (i.e. at the same index) value in `y` are both zeros.
Being `r` the value I want to use for the substitution, I want to achieve something logically equivalent to: `if x_i==0 and y_i == 0 then x_i = r`.

I tried with something like `x[x== 0 and y == 0] = r` but it is not working.
What is the cleanest way to do this?
Thank you

Your solution is close. Instead of `and`, you should use `&`.

``````a = x==0
b = y==0
x[a & b] = r
``````