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
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
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
>
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
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
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 '
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