[Numpy-discussion] Funny business with 'is' operator?

Charles R Harris charlesr.harris at gmail.com
Fri Sep 6 12:32:12 EDT 2013


On Fri, Sep 6, 2013 at 10:19 AM, James Bergstra
<bergstrj at iro.umontreal.ca>wrote:

> Hi, could someone help me understand why this assertion fails?
>
> def test_is(self):
>     a = np.empty(1)
>     b = np.empty(1)
>     if a.data is not b.data:
>         assert id(a.data) != id(b.data) # <-- fail
>
> I'm trying to write an alternate may_share_memory function.
>
>
id seems not as advertised:

In [22]: for i in range(10): print id(a.data)
66094640
66095792
66095792
66095792
66095792
66095792
66094640
66094640
66094640
66094640

Not sure why.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130906/fc0e3ff4/attachment.html>


More information about the NumPy-Discussion mailing list