[Numpy-discussion] Bug: extremely misleading array behavior
eric
eric at enthought.com
Sat Jun 1 13:48:55 CDT 2002
----- Original Message -----
From: "Konrad Hinsen" <hinsen at cnrs-orleans.fr>
To: "Pearu Peterson" <pearu at cens.ioc.ee>
Cc: <numpy-discussion at lists.sourceforge.net>
Sent: Wednesday, May 29, 2002 4:08 AM
Subject: Re: [Numpy-discussion] Bug: extremely misleading array behavior
> Pearu Peterson <pearu at cens.ioc.ee> writes:
>
> > an array with 0 rank. It seems that the Numeric documentation is missing
> > (though, I didn't look too hard) the following rules of thumb:
> >
> > If `a' is rank 1 array, then a[i] is Python scalar or object. [MISSING]
>
> Or rather:
>
> - If `a' is rank 1 array with elements of type Int, Float, or Complex,
> then a[i] is Python scalar or object. [MISSING]
>
> - If `a' is rank 1 array with elements of type Int16, Int32, Float32, or
> Complex32, then a[i] is a rank 0 array. [MISSING]
>
> - If `a' is rank > 1 array, then a[i] is a sub-array a[i,...]
>
> The rank-0 arrays are the #1 question topic for users of my netCDF
> interface (for portability reasons, netCDF integer arrays map to
> Int32, not Int, so scalar integers read from a netCDF array are always
> rank-0 arrays), and almost everybody initially claims that it's a bug,
> so some education seems necessary.
I don't think education is the answer here. We need to change Numeric to have
uniform behavior across all typecodes.
Having alternative behaviors for indexing based on the typecode can lead to very
difficult to find bugs. Generic routines meant to work with any Numeric type can
brake a year later when someone passes in an array with a seemingly compatible
type. Also, because coersion can silently change typecodes during arithmetic
operations, code written expecting one behavior can all the sudden exihibit the
other. That is very dangerous and hard to test.
eric
More information about the Numpy-discussion
mailing list