[SciPy-User] Matrix Element Comparison
Tue Oct 20 15:27:21 CDT 2009
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)
"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
More information about the SciPy-User