[Numpy-discussion] Masked Array Usage Problems
Sat Apr 10 07:17:31 CDT 2010
On Sat, Apr 10, 2010 at 3:49 AM, Lane Brooks <email@example.com> 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 ~597.
> 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?
> NumPy-Discussion mailing list
More information about the NumPy-Discussion