On 2014/03/13 9:09 PM, Sudheer Joseph wrote:

Dear Oslen,

I had a detailed look at the example you send and points I got were below

a = np.arange(-8, 8).reshape((4, 4)) b = ma.masked_array(a, mask=a < 0)

Out[33]: b[b<4] masked_array(data = [-- -- -- -- -- -- -- -- 0 1 2 3], mask = [ True True True True True True True True False False False False], fill_value = 999999) In [34]: b[b<4].shape Out[34]: (12,) In [35]: b[b<4].data Out[35]: array([-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3])

This shows while numpy can do the bolean operation and list the data meeting the criteria( by masking the data further), it do not actually allow us get the count of data that meets the crieteria. I was interested in count. Because my objective was to find out how many numbers in the grid fall under different catagory.( <=4 , >4 & <=8 , >8<=10) etc. and find the percentage of them.

Is there a way to get the counts correctly ? that is my botheration now !!

Certainly. If all you need are statistics of the type you describe, where you are working with a 1-D array, then extract the unmasked values into an ordinary ndarray, and work with that: a = np.random.randn(100) am = np.ma.masked_less(a, -0.2) print am.count() # number of masked values a_nomask = am.compressed() print type(a_nomask) print a_nomask.shape # number of points with value less than 0.5: print (a_nomask < 0.5).sum() # (Boolean True is 1) # Or if you want the actual array of values, not just the count: a_nomask[a_nomask < 0.5] Eric

with best regards, Sudheer