Subject: is ndarray.base the closest base or the ultimate base? Newsgroups: gmane.comp.python.numeric.general Date: Monday 21st September 2009 08:35:47 UTC (over 7 years ago) Hello, I cannot quite understand whether ndarray.base is the closest base, the one from which the view was made or the ultimate base, the one actually containing the data. I think the documentation and the actual behaviour mismatch. In [1]: import numpy as np In [2]: x = np.arange(12) In [3]: y = x[::2] In [4]: z = y[2:] In [5]: x.flags Out[5]: C_CONTIGUOUS : True F_CONTIGUOUS : True OWNDATA : True WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False In [6]: y.flags Out[6]: C_CONTIGUOUS : False F_CONTIGUOUS : False OWNDATA : False WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False In [7]: z.flags Out[7]: C_CONTIGUOUS : False F_CONTIGUOUS : False OWNDATA : False WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False In [8]: z.base Out[8]: array([ 0, 2, 4, 6, 8, 10]) It looks like the "base" of "z" is "y", i.e. its closest base, the array from which the view "z" was created. But the documentation says: base : ndarray If the array is a view on another array, that array is its `base` (unless that array is also a view). The `base` array is where the array data is ultimately stored. and it looks like the "base" should be "x", the array where the data is ultimately stored. I like the second one better. First, because this way I do not have to travel all the bases until I find an array with OWNDATA set. Second, because the current implementation keeps "y" alive because of "z" while in the end "z" only needs "x". In [11]: del y In [12]: z.base Out[12]: array([ 0, 2, 4, 6, 8, 10]) Comments? Best, Luca |
|||