[Numpy-discussion] weird problem with subtracting ndarrays

josef.pktd@gmai... josef.pktd@gmai...
Wed Jun 12 14:30:49 CDT 2013


On Wed, Jun 12, 2013 at 3:25 PM, Moroney, Catherine M (398D)
<Catherine.M.Moroney@jpl.nasa.gov> wrote:
> Hello,
>
> I've got two arrays of the same shape that I read in from a file, and I'm trying to
> difference them.  Very simple stuff, but I'm getting weird answers.
>
> Here is the code:
>
>>>> counts1 = hfile1.read_grid_field("CFbA", "TerrainReferencedRCCMFraction_Num")
>>>> counts2 = hfile2.read_grid_field("CFbA", "TerrainReferencedRCCMFraction_Num")
>>>> counts1.max(), counts2.max()
> (13, 13)
>>>> counts1.min(), counts2.min()
> (0, 0)
>>>> numpy.all(counts1 == counts2)
> False
>>>> diff = counts1 - counts2
>>>> diff.max()
> 4294967295      !! WHAT IS HAPPENING HERE ??
>>>> sum = counts1 + counts2
>>>> sum.max()
> 26
>
> As you can see, the range of values in both arrays is 0 to 13, and the sum
> behaves normally, but the difference gives this weird number.
>
> When I create dummy arrays, the subtraction works fine.  So there must be some funny value
> lurking in either the counts1 or counts2 array, but the numpy.isnan() test returns False.
>
> Any ideas for how I debug this?

check the dtype of the count variables, may be uint

diff =1 *  counts1 - counts2

Josef

>
> Catherine
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion


More information about the NumPy-Discussion mailing list