Re: [Numpy-discussion] Determining the 'viewness' of an array, and flags.owndata confusion

2012-02-28 Thread Val Kalatsky
Viewness is in the eyes of the beholder. You have to use indirect methods to figure it out. Probably the most robust approach is to go up the base chain until you get None. In [71]: c1=np.arange(16) In [72]: c2=c1[::2] In [73]: c4=c2[::2] In [74]: c8=c4[::2] In [75]: id(c8.base)==id(c4) Out[75]: T

Re: [Numpy-discussion] Determining the 'viewness' of an array, and flags.owndata confusion

2012-02-28 Thread Jonathan Rocher
Thank you all for your answers. Kurt and I were training new developers on numpy and telling them that - fancy indexing creates a copy - owndata was a good way to know if an array is a view or a copy. It turns out that these were both correct statements but we didn't think that the fancy indexing w

Re: [Numpy-discussion] Determining the 'viewness' of an array, and flags.owndata confusion

2012-02-28 Thread Nathaniel Smith
On Tue, Feb 28, 2012 at 11:01 PM, Kurt Smith wrote: > For an arbitrary numpy array 'a', what does 'a.flags.owndata' indicate? I think what it really indicates is whether a's destructor should call free() on a's data pointer. > I originally thought that owndata is False iff 'a' is a view.  But >

Re: [Numpy-discussion] Determining the 'viewness' of an array, and flags.owndata confusion

2012-02-28 Thread Robert Kern
On Tue, Feb 28, 2012 at 23:01, Kurt Smith wrote: > For an arbitrary numpy array 'a', what does 'a.flags.owndata' indicate? > > I originally thought that owndata is False iff 'a' is a view.  But > that is incorrect. > > Consider the following: > > In [119]: a = np.zeros((3,3)) > > In [120]: a.flags

Re: [Numpy-discussion] Determining the 'viewness' of an array, and flags.owndata confusion

2012-02-28 Thread Kurt Smith
On Tue, Feb 28, 2012 at 5:12 PM, Larsen, Brian A wrote: > Stack overflow post related to this: > http://stackoverflow.com/questions/9164269/can-you-tell-if-an-array-is-a-view-of-another They recommend testing "a.base". However, in the example I posted, "a.base" is not reliable either. For examp

Re: [Numpy-discussion] Determining the 'viewness' of an array, and flags.owndata confusion

2012-02-28 Thread Larsen, Brian A
Stack overflow post related to this: http://stackoverflow.com/questions/9164269/can-you-tell-if-an-array-is-a-view-of-another On Feb 28, 2012, at 4:01 PM, Kurt Smith wrote: For an arbitrary numpy array 'a', what does 'a.flags.owndata' indicate? I originally thought that owndata is False iff '

[Numpy-discussion] Determining the 'viewness' of an array, and flags.owndata confusion

2012-02-28 Thread Kurt Smith
For an arbitrary numpy array 'a', what does 'a.flags.owndata' indicate? I originally thought that owndata is False iff 'a' is a view. But that is incorrect. Consider the following: In [119]: a = np.zeros((3,3)) In [120]: a.flags.owndata # should be True; zeros() creates and returns a non-view