[SciPy-User] Matrix Element Comparison

Bruce Ford bruce@clearscienceinc....
Tue Oct 20 15:23:44 CDT 2009

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!


Bruce W. Ford
Clear Science, Inc.

More information about the SciPy-User mailing list