[Numpy-discussion] Checking for views (was: Should arr.diagonal() return a copy or aview?)

Benjamin Root ben.root at ou.edu
Thu May 24 11:04:55 EDT 2012


On Thu, May 24, 2012 at 10:56 AM, Jonathan T. Niehof <jniehof at lanl.gov>wrote:

> On 05/23/2012 05:31 PM, T J wrote:
>
> > It seems that there are a number of ways to check if an array is a view.
> > Do we have a preferred way in the API that is guaranteed to stay
> > available? Or are all of the various methods "here to stay"?
>
> We've settled on checking array.base, which I think was the outcome of a
> stackoverflow thread that I can't dig up. (I'll check with the guy who
> wrote the code.)
>
>
Just as a quick word to the wise.  I think I can recall a situation where
this could be misleading.  In particular, I think it had to do with
boolean/fancy indexing of an array.  In some cases, what you get is a view
of the copy of the original data.  So, if you simply check to see if it is
a view, and then assume that because it is a view, it must be a view of the
original data, then that assumption can come back and bite you in strange
ways.

Cheers!
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120524/839aa601/attachment.html>


More information about the NumPy-Discussion mailing list