[Numpy-discussion] Masked Array Usage Problems
Sun Apr 11 00:10:28 CDT 2010
On Sun, Apr 11, 2010 at 1:00 AM, Lane Brooks <firstname.lastname@example.org> wrote:
> On Apr 10, 2010, at 5:17 AM, email@example.com wrote:
>> On Sat, Apr 10, 2010 at 3:49 AM, Lane Brooks <firstname.lastname@example.org> wrote:
>>> I am trying out masked arrays for the first time and having some
>>> problems. I have a 2-D image as dtype=numpy.int16
>>> I create a mask of all False to not mask out any pixels.
>>> I calculate the mean of the image original image and it comes out
>>> I calculate the mean of the masked array and it comes out differently
>>> around -179. It produces the same negative mean value no matter what
>>> masks I try, e.g. (all True, all False, etc). Furthermore there
>>> are no
>>> negative samples in the entire array.
>>> Any ideas on what am I doing wrong?
>>> Here is some sample code showing the behavior:
>>> In : img.dtype, img.shape
>>> Out: (dtype('int16'), (3200, 3456))
>>> In : mask = numpy.zeros(img.shape, dtype=bool)
>>> In : imgma = ma.masked_array(img, mask)
>>> In : img.mean()
>>> Out: 597.15437617549185
>>> In : imgma.mean()
>>> Out: -179.56858678747108
>>> In : imgma.min()
>>> Out: 25
>>> In : numpy.__version__
>>> Out: '1.3.0'
>>> In : numpy.ma.__version__
>>> Out: '1.0'
>> Just a guess untill Pierre replies:
>> It looks to me like an integer overflow bug. Can you try
>> to do the accumulation with floating points?
> Indeed using dtype=float solved the problem. The numpy.mean doc string
> says the default accumulator type for all int types is a float. Why is
> ma.mean different, especially since the ma.mean doc string says to
> see the numpy.mean doc string?
I think it is a bug in ma.mean, since the docstring clearly specifies
the casting to float.
Can you file a ticket? I think Pierre will look at it when he finds time.
> NumPy-Discussion mailing list
More information about the NumPy-Discussion