Even if it's unlikely to happen, y[cond] might become a view of y and thus y will be overwritten. So, on a second thought, I think it would be safer to always allocate y_binary with np.empty (i.e., remove the if statement).