Do we need to test this each iteration? Would a rr, cc = np.nonzero(mask) and a subsequent iteration through all nonzero elements be sufficient?