[Numpy-discussion] How to detect ndarrays pointing to the same memory?

Hans Meine meine@informatik.uni-hamburg...
Fri Jul 17 09:30:38 CDT 2009


Hi,

I have a simple question: How can I detect whether two arrays share the same 
data?

>>> a =  numpy.arange(10)
>>> b = a.view(numpy.ndarray)
>>>
>>> a is not b # False, as expected
True
>>> a.data is b.data # I expected this to be True
False
>>>
>>> a.data
<read-write buffer for 0x8a6920, size 80, offset 0 at 0x7fad2536c4b0>
>>> b.data # even the memory addresses differ?!
<read-write buffer for 0x894810, size 80, offset 0 at 0x7fad2536c4f0>
>>>
>>> a.data[4] = "\x55"
>>> b.data[4] == "\x55" # yes, the buffers point to the same data
True

Ciao,
 Hans


More information about the NumPy-Discussion mailing list