On Mar 13, 2014, at 9:39 AM, Nicolas Rougier <[email protected]> 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 <[email protected]> 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:[email protected];[email protected]
>> Web- http://oppamthadathil.tripod.com
>> ***************************************************************<r2010.nc>_______________________________________________
>> NumPy-Discussion mailing list
>> [email protected]
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
> _______________________________________________
> NumPy-Discussion mailing list
> [email protected]
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to