[Numpy-discussion] python array

Sudheer Joseph sudheer.joseph at yahoo.com
Thu Mar 13 21:09:34 EDT 2014


Thank you very much Nicolas and Chris,
                             The hint was helpful and from that I treid below steps ( a crude way I would say) and getting same result now

I have been using abs available by default and it is the same with numpy.absolute( i checked).

nr= ((r2010>r2010.min()) & (r2010<r2010.max()))
nr[nr<.5].shape
Out[25]: (33868,)
anr=numpy.absolute(nr)
anr[anr<.5].shape
Out[27]: (33868,)

This way I used may have problem when mask used has values which can affect the min max operation.

So I would like to know if there is a standard formal ( python/numpy) way to handle masked array when they need to be subjected to boolean operations.

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 at gmail.com;sudheer.joseph at yahoo.com
Web- http://oppamthadathil.tripod.com
***************************************************************

--------------------------------------------
On Thu, 13/3/14, Chris Barker - NOAA Federal <chris.barker at noaa.gov> wrote:

 Subject: Re: [Numpy-discussion] python array
 To: "Discussion of Numerical Python" <numpy-discussion at scipy.org>
 Date: Thursday, 13 March, 2014, 11:53 PM
 
 On Mar 13, 2014, at 9:39 AM, Nicolas
 Rougier <Nicolas.Rougier at inria.fr>
 wrote:
 
 >
 > Seems to be related to the masked values:
 
 Good hint -- a masked array keeps the "junk" values in the
 main array.
 
 What "abs" are you using -- it may not be mask-aware. ( you
 want a
 numpy abs anyway)
 
 Also -- I'm not sure I know what happens with Boolean
 operators on
 masked arrays when you use them to index. I'd investigate
 that.
 (sorry, not at a machine I can play with now)
 
 Chris
 
 
 > print r2010[:3,:3]
 > [[-- -- --]
 > [-- -- --]
 > [-- -- --]]
 >
 > print abs(r2010)[:3,:3]
 > [[-- -- --]
 > [-- -- --]
 > [-- -- --]]
 >
 >
 > print r2010[ r2010[:3,:3] <0 ]
 > [-- -- -- -- -- -- -- -- --]
 >
 > print r2010[ abs(r2010)[:3,:3] < 0]
 > []
 >
 > Nicolas
 >
 >
 >
 > On 13 Mar 2014, at 16:52, Sudheer Joseph <sudheer.joseph at yahoo.com>
 wrote:
 >
 >> Dear experts,
 >>             
        I am encountering a strange
 behaviour of python data array as below. I have been trying
 to use the data from a netcdf file(attached herewith) to do
 certain calculation using below code. If I take absolute
 value of the same array and look for values <.5  I
 get a different value than the original array. But the fact
 is that this particular case do not have any negative values
 in the array( but there are other files where it can have
 negative values so the condition is put). I do not see any
 reason for getting different numbers for values <.5 in
 case of bt and expected it to be same as that of r2010. If
 any one has a guess on what is behind this behaviour please
 help.
 >>
 >>
 >> In [14]: from netCDF4 import Dataset as nc
 >>
 >> In [15]: nf=nc('r2010.nc')
 >> In [16]: r2010=nf.variables['R2010'][:]
 >> In [17]: bt=abs(r2010)
 >> In [18]: bt[bt<=.5].shape
 >> Out[18]: (2872,)
 >> In [19]: r2010[r2010<.5].shape
 >> Out[19]: (36738,)
 >>
 >>
 >> bt.min()
 >> Out[20]: 0.0027588337040836768
 >>
 >> In [21]: bt.max()
 >> Out[21]: 3.5078965479057089
 >> In [22]: r2010.max()
 >> Out[22]: 3.5078965479057089
 >> In [23]: r2010.min()
 >> Out[23]: 0.0027588337040836768
 >>
 >>
 >>
 >>
 ***************************************************************
 >> 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 at gmail.com;sudheer.joseph at yahoo.com
 >> Web- http://oppamthadathil.tripod.com
 >>
 ***************************************************************<r2010.nc>_______________________________________________
 >> NumPy-Discussion mailing list
 >> NumPy-Discussion at scipy.org
 >> http://mail.scipy.org/mailman/listinfo/numpy-discussion
 >
 > _______________________________________________
 > NumPy-Discussion mailing list
 > NumPy-Discussion at scipy.org
 > http://mail.scipy.org/mailman/listinfo/numpy-discussion
 _______________________________________________
 NumPy-Discussion mailing list
 NumPy-Discussion at scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
 



More information about the NumPy-Discussion mailing list