[Numpy-discussion] Empty arrays strange behaviour

Todd Miller jmiller at stsci.edu
Wed Aug 18 10:26:12 EDT 2004


On Wed, 2004-08-18 at 11:42, Tim Hochberg wrote:
> Todd Miller wrote:
> 
> 
> [CHOP]
> 
> >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
> >semantics.
> >
> >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).
> 
> -tim
> 
>  >>> import Numeric as np
>  >>> np.zeros([0])
> zeros((0,), 'l')
>  >>> np.zeros([0,2])
> zeros((0, 2), 'l')
>  >>> import numarray as na
>  >>> na.zeros([0])
> array([])
>  >>> na.zeros([0,2])
> array([])
>  >>> na.arange(100)
> 
> 
OK, I logged this on SF.   Thanks for the explanation.

Todd





More information about the NumPy-Discussion mailing list