[Numpy-discussion] Numeric array's actual data address?
jmiller at stsci.edu
Tue Feb 1 05:09:08 EST 2005
On Mon, 2005-01-31 at 17:04 -0800, Ray S wrote:
> If I have an array N:
> >>> N = Numeric.zeros((1000,), Numeric.Float)
> >>> repr(N.__copy__)
> '<built-in method __copy__ of array object at 0x00809F00>'
> What is the actual address of the first element?
In C, look at a->data.
> Or, as an offset from the
This doesn't really make sense given the layout of the objects and how
the memory is stored. You should probably read over the section on the
C-API in the Numeric and numarray manuals. The Numeric manual, here,
is probably the best place to start because it is the simplest:
The numarray manual, here:
has a section on a Numeric compatibility layer which is very similar.
> numarray gives us that:
> >>> N = numarray.zeros((1000,), numarray.Float)
> >>> N.info()
> class: <class 'numarray.numarraycore.NumArray'>
> shape: (1000,)
> strides: (8,)
> byteoffset: 0
> bytestride: 8
> itemsize: 8
> aligned: 1
> contiguous: 1
> data: <memory at 009d67b8 with size:8000 held by object 009d6798 aliasing
> object 00000000>
> byteorder: little
> byteswap: 0
> type: Float64
> In numarray, the offset appears to be 20.
> If I try to use memmove() to fill a Numeric array it faults when using an
> offset of 20...
The offset of 0x20 is unique to the numarray.memory memory object. It
has nothing to do with Numeric arrays so it could only work by accident.
Note that the "data" section of numarray's info() is referring to a
buffer object which is stored in the _data attribute. I just changed
the info() to avoid this confusion in the future by renaming "data" to
"buffer". From the overall perspective of the array object, the
"working data pointer" (a->data in C) is the sum of the byteoffset and
_data base pointer.
In response to this post, I modified info() to the following:
>>> import numarray as na
>>> a = na.arange(10)
class: <class 'numarray.numarraycore.NumArray'>
buffer: <memory at 0xb7c07f68 with size:0x00000028 held by object 0xb7f8d5a0 aliasing object 0x00000000>
fragile data pointer: 0xb7c07f68 (DEBUG ONLY)
I think the "fragile data pointer" is generally useful information, but
not completely dependable so I gave it the garish name it has.
More information about the NumPy-Discussion