I was playing with id()
function in python. I got some interesting observations.
See the piece of code given below:
#Python Code
import numpy as np
x = np.arange(1,10)
x = np.reshape(x, (3,3))
# x is array([[ 1, 2, 3], [ 4, 5, 6], [ 7, 8, 9]])
y = x[:2,1:]
y[1,0] = 50
# Now y is array([[ 2, 3], [50, 6]])
# and x is array([[ 1, 2, 3], [ 4, 50, 6], [ 7, 8, 9]])
yc = np.copy(x[:2,1:])
yc[0,1] = 300
# Now y is array([[ 2, 3], [50, 6]])
# and x is array([[ 1, 2, 3], [ 4, 50, 6], [ 7, 8, 9]])
# and yc is array([[ 2, 300], [50, 6]]) '''
print(id(x[0,2]), id(y[0,1]), id(yc[0,1]))
#170516080 170516080 170516080
#All are same !!
id(x[0,2]) == id(yc[0,1])
#True
x[0,2] is yc[0,1]
#False
So how is
is different form id(obj1) == id(obj2)
?
Can anyone explain this?