[Numpy-discussion] Accessing array members

David M. Cooke cookedm at arbutus.physics.mcmaster.ca
Tue Dec 3 14:40:02 EST 2002

On Tue, Dec 03, 2002 at 11:03:20AM +0100, Konrad Hinsen wrote:
> cookedm at arbutus.physics.mcmaster.ca (David M. Cooke) writes:
> > The idea is that a PyArrayObject has a member 'base', which is DECREF'd
> > when the array is deallocated. The idea is for when arrays are slices of
> Indeed, but this is an undocumented implementation feature. Use at your
> own risk.

Nope, documented implementation feature. From the C API documentation,

  PyObject  * base

  Used internally in arrays that are created as slices of other arrays.
  Since the new array shares its data area with the old one, the original
  array's reference count is incremented. When the subarray is garbage
  collected, the base array's reference count is decremented.

Looking through Numeric's code, nothing requires base to be an array
object.  Besides, Numeric isn't going to change substantially before
Numarray replaces it (although I don't know the analogue of this trick
in Numarray).

The usefulness of this trick (IMHO) outweighs the small chance of the
interface changing.

|David M. Cooke                 http://arbutus.physics.mcmaster.ca/cookedm/
|cookedm at physics.mcmaster.ca

More information about the NumPy-Discussion mailing list