[Numpy-discussion] Empty arrays strange behaviour

Todd Miller jmiller at stsci.edu
Wed Aug 18 08:31:05 CDT 2004


On Wed, 2004-08-18 at 11:16, Alan G Isaac wrote:
> >> I'd say we should go with compatibility.
> >> Todd
> 
> 
> Script:
> a=[[i+i*j for i in range(5)]for j in range(4)]
> print a[2:4][5:7]
> import Numeric
> b=Numeric.array(a)
> print b[2:4,5:7]
> import numarray
> c=numarray.array(a)
> print c[2:4,5:7]
> 
> Output:
> []
> zeros((2, 0), 'l')
> []
> 

You've got something of a point here,  if you're trying to say that
compatibility isn't perfect anyway.

Here's what I meant:

>>> from numarray import * 
>>> a = arange(20)
>>> a.shape = (4,5)
>>> a[2:4,5:7]
array([])
>>> a[2:4,5:7].info()
class: <class 'numarray.numarraycore.NumArray'>
shape: (2, 0)
strides: (20, 4)
byteoffset: 60
bytestride: 4
itemsize: 4
aligned: 1
contiguous: 0
data: <memory at 0x404c0298 with size:0x00000050 held by object 0x401839c8 aliasing object 0x00000000>
byteorder: little
byteswap: 0
type: Int32

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.

Regards,
Todd






More information about the Numpy-discussion mailing list