Use valid or ~isfinite might be a more generic way to do this. `flag[ma.getmaskarray(data[v])] = 9`