![](https://secure.gravatar.com/avatar/484a095079f0f31c78f2e3439f34d1d5.jpg?s=120&d=mm&r=g)
Hi All, I have an 2D numeric array of x,y points eg [(1,3),(2,4),(5,6)] and I would like to remove all the points in the array that don't meet the min/max point criteria. I will have several thousand points. With lists I can do it like [(x,y) for x,y in seq if xMin < x <xMax and yMin< y <yMax] How do I get the same functionality and better speed using numeric. I have tried a bunch of things using compress and take but I am running up against a brick wall. Any ideas? Thanks Gordon Williams
![](https://secure.gravatar.com/avatar/5b2449484c19f8e037c5d9c71e429508.jpg?s=120&d=mm&r=g)
Gordon Williams wrote:
I think you want something like this:
Where 'a' is your original Nx2 array. Unfortunately the obvious notation and prettier notation using (xMin < a[:,0] < xMax) fails because python treats that as "(xMin < a[:,0]) and (a[:,0] < xMax)" and "and" is not what you need here, '&' is. -tim
![](https://secure.gravatar.com/avatar/5dde29b54a3f1b76b2541d0a4a9b232c.jpg?s=120&d=mm&r=g)
On Thursday, February 27, 2003, at 11:05 AM, Gordon Williams wrote:
This should do it:
Note that & is a bitwise-and, not a logical and, but in this case, the result is the same. Unfortunately, the way Python works, overloading "and" is difficult. -Chris Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
![](https://secure.gravatar.com/avatar/5b2449484c19f8e037c5d9c71e429508.jpg?s=120&d=mm&r=g)
Gordon Williams wrote:
I think you want something like this:
Where 'a' is your original Nx2 array. Unfortunately the obvious notation and prettier notation using (xMin < a[:,0] < xMax) fails because python treats that as "(xMin < a[:,0]) and (a[:,0] < xMax)" and "and" is not what you need here, '&' is. -tim
![](https://secure.gravatar.com/avatar/5dde29b54a3f1b76b2541d0a4a9b232c.jpg?s=120&d=mm&r=g)
On Thursday, February 27, 2003, at 11:05 AM, Gordon Williams wrote:
This should do it:
Note that & is a bitwise-and, not a logical and, but in this case, the result is the same. Unfortunately, the way Python works, overloading "and" is difficult. -Chris Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
participants (3)
-
Chris Barker
-
Gordon Williams
-
Tim Hochberg