ID of an array element changes in IPython

Viewed 913

Why does ID of array element keeps on changing?

    In [43]: x = np.array([[1,2,3],[4,5,6],[7,8,9]])
    In [44]: print id(x[0])
    30836416
    In [45]: print id(x[0])
    31121344
    In [46]: print id(x[0])
    31471808

IPython Screenshot

This is not the case when it is written in a python script When written in python script we get the same ID Python script screenshot

And also other observation is in the below figure Behaviour when printed ID of copy of the array for the same element

aCopy is the copy of the array a. id for the same element of both the arrays is printed twice. According to the output, id of all the array elements whether it may be of the same array or different (copy) is same except for the FIRST print. Why id of same element of two different arrays are same? Why one of the id when printed multiple times is different?

2 Answers
Related