I am trying to understand the meaning of ndarray.data field in numpy (see memory layout section of the reference page on N-dimensional arrays), especially for views into arrays. To quote the documentation:
ndarray.data -- Python buffer object pointing to the start of the array’s data
According to this description, I was expecting this to be a pointer to the C-array underlying the instance of ndarray.
Consider x = np.arange(5, dtype=np.float64).
Form y as a view into x using a slice: y = x[3:1:-1].
I was expecting x.data to point at location of 0. and y.data to point at the location of 3.. I was expecting the memory pointer printed by y.data to thus be offset by 3*x.itemsize bytes from the memory pointer printed by x.data, but this does not appear to be the case:
>>> import numpy as np
>>> x = np.arange(5, dtype=np.float64)
>>> y = x[ 3:1:-1]
>>> x.data
<memory at 0x000000F2F5150348>
>>> y.data
<memory at 0x000000F2F5150408>
>>> int('0x000000F2F5150408', 16) - int('0x000000F2F5150348', 16)
192
>>> 3*x.itemsize
24
The 'data' key in __array_interface dictionary associated with the ndarray instance behaves more like I expect, although it may itself not be a pointer:
>>> y.__array_interface__['data'][0] - x.__array_interface__['data'][0]
24
So this begs the question, what does the
ndarray.datagive?
Thanks in advance.
yis non-continuous, it doesn't exposedata(>>>y.data AttributeError: cannot get single-segment buffer for discontiguous array). So I kinda cannot imagine how you're going to comparex.dataandy.data. (numpy 1.11.1andpython 2.7.12 win32here) .y.datausing numpy 1.11 on Windows and Linux using Python 3.5.2 from Anaconda distribution. What is your configuration?