
Dear Oslen,
I had a detailed look at the example you send and
Thank you Eric, The compress is the option which is gets the correct numbers. a = np.arange(-8, 8).reshape((4, 4)) In [67]: b = ma.masked_array(a, mask=a < 0) In [68]: bb=b.compressed() In [69]: b[b<4].size Out[69]: 12 In [70]: bb=b.compressed() In [71]: bb[bb<=4].size Out[71]: 5 with best regards, Sudheer *************************************************************** Sudheer Joseph Indian National Centre for Ocean Information Services Ministry of Earth Sciences, Govt. of India POST BOX NO: 21, IDA Jeedeemetla P.O. Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55 Tel:+91-40-23886047(O),Fax:+91-40-23895011(O), Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile) E-mail:sjo.India@gmail.com;sudheer.joseph@yahoo.com Web- http://oppamthadathil.tripod.com *************************************************************** -------------------------------------------- On Fri, 14/3/14, Eric Firing <efiring@hawaii.edu> wrote: Subject: Re: [Numpy-discussion] python array To: numpy-discussion@scipy.org Date: Friday, 14 March, 2014, 7:20 AM On 2014/03/13 9:09 PM, Sudheer Joseph wrote: 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],
fill_value =
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
mask = [ True True True True True True True True False False False False], 999999) 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
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion