Solved by JuanFMontesinos in post #4 
              
              
                I don’t understand at all why you need to do a nested loop. You are not permuting indices and you are always taking i,j,k in an ordered way. You can just do something like 
mask = target[...,4]>0 |  target[...,9]
object[mask]=1
object[mask.expand_as(object_temp)]=1