[SciPy-User] Matrix Element Comparison

Bruce Ford bruce@clearscienceinc....
Tue Oct 20 16:19:13 CDT 2009


That is elegant.  I'm not finding much in the docs about this kind of operator.

Thanks much!
---------------------------------------
Bruce W. Ford
Clear Science, Inc.
bruce@clearscienceinc.com
bruce.w.ford.ctr@navy.smil.mil
http://www.ClearScienceInc.com
Phone/Fax: 904-379-9704
8241 Parkridge Circle N.
Jacksonville, FL  32211
Skype:  bruce.w.ford
Google Talk: fordbw@gmail.com



On Tue, Oct 20, 2009 at 4:27 PM, Robert Kern <robert.kern@gmail.com> wrote:
> On Tue, Oct 20, 2009 at 15:23, Bruce Ford <bruce@clearscienceinc.com> wrote:
>> There must be an elegant way to do this, but I've been staring at
>> Numpy functions to no avail.
>>
>> I want to great a matrix that counts the number of times a condition
>> is met for each grid point.
>>
>> print grid.shape   # print (31,18)
>> count_grid = np.zeros_like(grid)  #new grid for counting
>> exceed = 1
>>
>> I want to do an element-by-element comparison and when a gridpoint
>> value is > 1, add one to count_grid at that same grid point.
>>
>> I'm looking for an elegant way to do something like this in an
>> element-wise fashion...
>>
>> if grid>exceed:
>>    count_grid = count_grid+1
>>
>> Any points in the right direction would be appreciated!
>
> count_grid += (grid > exceed)
>
> --
> 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
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-User mailing list