I would choose a different name for this method or describe it more completely; I'm not entirely clear what `scan` is supposed to do.  Maybe `create_mask`?  

Should the returned `mask` be a boolean array, or is it, e.g., an array with 0's and, say, 5's?