[SciPy-User] Matrix Element Comparison
Tue Oct 20 16:19:13 CDT 2009
That is elegant. I'm not finding much in the docs about this kind of operator.
Bruce W. Ford
Clear Science, Inc.
8241 Parkridge Circle N.
Jacksonville, FL 32211
Google Talk: firstname.lastname@example.org
On Tue, Oct 20, 2009 at 4:27 PM, Robert Kern <email@example.com> wrote:
> On Tue, Oct 20, 2009 at 15:23, Bruce Ford <firstname.lastname@example.org> 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
More information about the SciPy-User