Subject: is ndarray.base the closest base or the ultimate base?
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 : import numpy as np In : x = np.arange(12) In : y = x[::2] In : z = y[2:] In : x.flags Out: C_CONTIGUOUS : True F_CONTIGUOUS : True OWNDATA : True WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False In : y.flags Out: C_CONTIGUOUS : False F_CONTIGUOUS : False OWNDATA : False WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False In : z.flags Out: C_CONTIGUOUS : False F_CONTIGUOUS : False OWNDATA : False WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False In : z.base Out: 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 : del y In : z.base Out: array([ 0, 2, 4, 6, 8, 10]) Comments? Best, Luca