In below example x is view of y. Why id(x[1,1]) and id(y[1,1]) are different? I experimented with array views, but I don't understand how it works.
import numpy as np
x=np.array([[1,2,3],[4,5,6],[7,8,9]])
y=x[0:2,0:2]
y.base # is x
id(x[1,1])
id(y[1,1])
idreturn the identity of the Numpy temporary object created fromx[1,1]. It is not the address of the cell. Numpy stores data in a C array that is not visible from CPython. You cannot directly access cells from CPython, but only from temporary CPython objects wrapping the information. Regarding the base pointer of the array, you can get it usingarr.__array_interface__['data'][0]id(x[1,1])can produce the same or different values each time it's called, depending on how the temporary object memory and id is recycled. So checking thebaseis the right thing to do (or__array_intercace__). Aviewdoes share the same dafa-buffer with its base. But neither stores list like references.idis virtually useless when applied to numpy objects.