[Numpy-discussion] Help making better use of numpy array functions

Pierre GM pgmdevlist@gmail....
Wed Nov 25 15:41:06 CST 2009


On Nov 25, 2009, at 4:13 PM, mdekauwe wrote:
> I tried redoing the internal logic for example by using the where function
> but I can't seem to work out how to match up the logic. For example (note
> slightly different from above). If I change the main loop to
> 
> lst = np.where((data > -900.0) & (lst < -900.0), data, lst)
> lst = np.where((data > -900.0) & (lst > -900.0), 5.0, lst)
> 
> If I then had a data array value of 10.0 and lst array value of -999.0. In
> this scenario the first statement would set the LST value to 10.0. However
> when you run the second statement, data is still bigger than the undefined
> (-999.0) but now so is the LST, hence the lst is set to 5.0
> 
> This doesn't match with the logic of            
> 
> if data[i,j] > -900.:
>    if lst[i,j] < -900.:
>        lst[i,j] = data[i,j]
>    elif lst[i,j] > -900.:
>        lst[i,j] = 5.0
> 
> as it would never get to the second branch under this logic.
> 
> Does anyone have any suggestions on how to match up the logic?
> 


np.where(data>-900,np.where(lst<-900,data,5.),lst)

Note that this should fail if lst=-900


More information about the NumPy-Discussion mailing list