[Numpy-discussion] Empty arrays strange behaviour
jmiller at stsci.edu
Wed Aug 18 10:26:12 CDT 2004
On Wed, 2004-08-18 at 11:42, Tim Hochberg wrote:
> Todd Miller wrote:
> >The key points for me are:
> >1. The slice operation doesn't raise an exception even though it has
> >"invalid" indexes. As Tim H. pointed out, those are standard Python
> >2. The shape of the resultant array is the same.
> >I don't know anything about the purpose of "zeros()" in this context. It
> >looks inconsistent to me.
> I believe it's to disambiguate the various possible arrays of total size
> zero. I like the Numeric behaviour better here, although it's not a big
> deal. In the following, both the size and type of the numarrays are
> ambiguous from their repr(). This means that among other things
> eval(repr(arg)) won't return arg even for nice short arrays (I realize
> the numarray truncates the reprs of long arrays by default and I think
> that's fine -- I imagine there's some way to disable it, but I haven't
> looked for it yet).
> >>> import Numeric as np
> >>> np.zeros()
> zeros((0,), 'l')
> >>> np.zeros([0,2])
> zeros((0, 2), 'l')
> >>> import numarray as na
> >>> na.zeros()
> >>> na.zeros([0,2])
> >>> na.arange(100)
OK, I logged this on SF. Thanks for the explanation.
More information about the Numpy-discussion