I have created 2 numpy arrays.
- Original
- Cloned
Cloned is a copy of original array. I changed an element in cloned array. I am checking id of original
and cloned
array using is keyword. It returns false
. But when I print id of both elements, it is same.
I know about peephole optimization techniques and numbers from -5 to 256 is stored at same address in python. But here I have changed value to 400 (> 256). Still it shows same id. WHY?
Please correct me if I am wrong. I am new to numpy arrays
import numpy as np
original = np.array([
[1, 2, 3, 4, 5],
[6, 7, 9, 10, 11]
])
# Copying array "original" to "cloned"
cloned = original.copy()
# Changing first element of Cloned Array
cloned[0, 1] = 400
print(id(cloned[0, 1]))
print(id(original[0, 1]))
print(id(cloned[0, 1]) is id(original[0, 1]))
Output:
140132171232408
id is same
140132171232408
id is same
False
is returns false although id is same