a = [5,6,7,8]
print('for list:')
for i in a:
print((id(i)))
import numpy as np
z = np.array([9,10,11,12])
print('for numpy:')
for i in z:
print((id(i)))
Note: When i am trying to see the memory address of the values in a list it takes contiguous memory of 32 bits. But when i am converting a list to a Numpy array and printing the address of the values, alternate values are taking same memory address. I don't understand why this is happening?
output:
for list:
94620302609024
94620302609056
94620302609088
94620302609120
for numpy:
139853895184240
139853895279216
139853895184240
139853895279216
As you can see for numpy array the memory address of the alternate values are same. Please explain me why this is happening?