[Numpy-discussion] detecting point out of bounds...

Robert Kern robert.kern@gmail....
Wed Jun 17 17:47:09 CDT 2009


On Wed, Jun 17, 2009 at 17:32, fred<fredmfp@gmail.com> wrote:
> Hi all,
>
> Let's say I have an array (n,3) ie x, y, v, in each row.
>
> How can I count the number of points (x,y) that are out of bounds (xmin,
> xmax) (ymin, ymax)?
>
> The following is obviously wrong:
>
>        n = (data[:, 0]<xmin).nonzero()[0].size + \
>            (data[:, 0]>xmax).nonzero()[0].size + \
>            (data[:, 1]<ymin).nonzero()[0].size + \
>            (data[:, 1]>ymax).nonzero()[0].size
>
> and I don't want to use a loop to count the number of bad points,
> of course.

((data[:,0]<xmin) | (data[:,0]>xmax) | (data[:,1]<ymin) |
(data[:,1]>ymax)).sum()

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the Numpy-discussion mailing list