[Numpy-discussion] Bug: extremely misleading array behavior

Pearu Peterson pearu at cens.ioc.ee
Tue May 28 13:32:03 EDT 2002


Hi Larry,

On Tue, 28 May 2002, Larry Denneau wrote:

> All the Numpy documentation examples (see
> http://pfdubois.com/numpy/html2/numpy-6.html#pgfId-36033, "Getting and
> Stting Array Values") use the [x, y] notation instead of [x][y], so I
> would consider this a bug in the documentation, since the [x, y]
> method leads to unexpected behavior.

If you look the section "Slicing Arrays" then a[1] is actually a[1,:],
that is, an one dimensional array. From your description, a[1,1] must be
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]
  If `a' is rank > 1 array, then a[i] is a sub-array a[i,...]

> I'm still curious what happens to the original array when 
> 
>   n=a[1, 1]
>   del(a)

I think the original array `a' is not actually deleted until `n' gets
deleted. If I recall correctly, then `n' is a sub-array of `a' so that
internally it contains only a reference to `a' in the sense that
a.data==n.data but strides and dimension arrays differ.

Pearu





More information about the NumPy-Discussion mailing list