From: Francesc A. <fa...@op...> - 2003-03-07 05:40:29
|
A Divendres 07 Mar=E7 2003 01:42, Sebastian Haase va escriure: > if I try to debug this by doing: > for z in range(nz): > print repr(arr[z]._data) > > that also tells be that python / numarray thinks all slices are located= at > the same address, that is: > every slice looks just like the full array. You can access the slices by taking into account the byte offset attribute. Look at the next example: In [20]: a=3Dnumarray.arange(100, shape=3D(10,10)) In [21]: a._data Out[21]: <memory at 083e58e8 with size:400 held by object at 083e58d0> In [22]: a[1]._data Out[22]: <memory at 083e58e8 with size:400 held by object at 083e58d0> as you already know, both memory buffers point to the same address. I gue= ss this is implemented in that way so as to not copy data unnecessarily. now, look at: In [23]: a._byteoffset Out[23]: 0 In [24]: a[1]._byteoffset Out[24]: 40 So, you can know where the data actually starts by looking at the _byteoffset property. In fact, you should always look at it in order to g= et proper results!. In C, you can access to this information by looking at the byteoffset fie= ld in the PyArrayObject struct (look at chapter 10 in the User's Manual). Hope that helps, --=20 Francesc Alted |