View Full Version : a little numpy/python enigma
stair314
June 11th, 2010, 05:15 PM
Anyone have an explanation for this?
>>> import numpy
>>> a = numpy.zeros((2,2))
>>> id(a[0,1])
27336416
>>> id(a[0,0])
26966160
>>> 27336416-26966160
370256
>>> id(a[0,1])-id(a[0,0])
0
Tony Flury
June 11th, 2010, 11:25 PM
interestingly - on my version of python 2.5.2 - the two ids are the same.
>>> import numpy
>>> a = numpy.zeros((2,2))
>>> a
array([[ 0., 0.],
[ 0., 0.]])
>>> id(a[0,1])
139961696
>>> id(a[0,0])
139961696
>>> id(a[0,0]) - id(a[0,1])
0
jpkotta
June 12th, 2010, 03:50 AM
Numpy must be making a new object every time you access an element of the array.
In [14]: id(a[0,1])
Out[14]: 161640272
In [15]: id(a[0,1])
Out[15]: 161097216
In [16]: id(a[0,1])
Out[16]: 162502440
In [17]: type(a[0,1])
Out[17]: <type 'numpy.float64'>
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.