Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #92146
| Date | 2015-06-05 06:23 -0700 |
|---|---|
| From | Gary Herron <gary.herron@islandtraining.com> |
| Subject | Re: So what's happening here? |
| References | <pan.2015.06.05.12.46.21@nowhere.invalid> <mailman.196.1433508938.13271.python-list@python.org> <pan.2015.06.05.13.11.13@nowhere.invalid> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.199.1433511337.13271.python-list@python.org> (permalink) |
On 06/05/2015 06:11 AM, Paul Appleby wrote: > On Fri, 05 Jun 2015 14:55:11 +0200, Todd wrote: > >> Numpy arrays are not lists, they are numpy arrays. They are two >> different data types with different behaviors. In lists, slicing is a >> copy. In numpy arrays, it is a view (a data structure representing some >> part of another data structure). You need to explicitly copy the numpy >> array using the "copy" method to get a copy rather than a view: > OK, thanks. I see. > > (I'd have thought that id(a[1]) and id(b[1]) would be the same if they > were the same element via different "views", but the id's seem to change > according to rules that I can't fathom.) Nope. It's odder than that. a[1] is still a view into the inderlying numpy array, and your id is the id of that view. Each such index produces a new such view object. Check this out: >>> import numpy >>> a = numpy.array([1,2,3]) >>> id(a[1]) 28392768 >>> id(a[1]) 28409872 This produces two different view of the same underlying object. Gary Herron
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
So what's happening here? Paul Appleby <pap@nowhere.invalid> - 2015-06-05 12:46 +0000
Re: So what's happening here? Fabien <fabien.maussion@gmail.com> - 2015-06-05 14:52 +0200
Re: So what's happening here? Larry Martell <larry.martell@gmail.com> - 2015-06-05 08:55 -0400
Re: So what's happening here? Peter Otten <__peter__@web.de> - 2015-06-05 15:09 +0200
Re: So what's happening here? Paul Appleby <pap@nowhere.invalid> - 2015-06-05 13:11 +0000
Re: So what's happening here? Gary Herron <gary.herron@islandtraining.com> - 2015-06-05 06:23 -0700
Re: So what's happening here? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 23:51 +1000
Re: So what's happening here? Nobody <nobody@nowhere.invalid> - 2015-06-05 15:13 +0100
csiph-web