[Numpy-discussion] scan array to extract min-max values (with if condition)

Massimo Di Stefano massimodisasha@gmail....
Sat Sep 11 16:46:49 CDT 2010


Thanks Pierre,

i tried it and all works fine and fast.

my apologize :-(

i used a wrong "if" statment to represent my needs

if mydata[i,0] < E or mydata[i,0] > W or mydata[i,1] < N or mydata[i,1] > S :

^^ totally wrong for my needs^^


this "if"  instead :

if W < mydata[i,0] < E and S < mydata[i,1] < N:

should reflect your example :

yselect = (data[:,1] <= N) & (data[:,1] >= S)
xselect = (data[:,0] <= E) & (data[:,0] >= W)
selected_data = data[xselect & yselect]


a question, how to code a masked array, 
as in the Brett's code, to reflect the new (right) if statment ?




i'm asking this to try to learn how to use masked array.
thanks a lot for your support!!!

Massimo.

Il giorno 11/set/2010, alle ore 23.00, Pierre GM ha scritto:

> 
> On Sep 11, 2010, at 9:53 PM, Massimo Di Stefano wrote:
> 
>> have you hints on how to get working the "MASK" code ?
>> as it is now it pick all the points in the "mydata" array.
> 
> Brett's code for the mask matched the loop of your post. However, taking a second look at it, I don't see why it would work. Mind trying something like
> 
> # Selection on the NS axis
> yselect = (mydata[:,1] <= N) & (mydata[:,1] >= S)
> # selection on the EW axis
> xselect = (mydata[:,1] <= E) & (mydata[:,1] >= W)
> # Global selection
> selected_data = mydata[xselect & yselect]
> 
> Now you can check in selected data that the coordinates are indeed in the rectangle that you want, and take the min/max of your data as needed.
> let me know how it goes
> 
> P.
> 
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion



More information about the NumPy-Discussion mailing list