Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92146

Re: So what's happening here?

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <gary.herron@islandtraining.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'see.': 0.07; "(i'd": 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'underlying': 0.09; 'index': 0.13; 'explicitly': 0.15; 'arrays,': 0.16; 'arrays.': 0.16; 'numpy': 0.16; 'received:67.192.241.150': 0.16; 'received:smtp150.dfw.emailsrvr.com': 0.16; 'wrote:': 0.16; 'element': 0.18; '>>>': 0.20; 'thanks.': 0.22; 'object.': 0.22; 'produces': 0.22; 'received:emailsrvr.com': 0.22; 'am,': 0.23; '2015': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'paul': 0.24; 'header:User-Agent:1': 0.26; 'rules': 0.27; '+0200,': 0.27; 'arrays': 0.29; 'subject:what': 0.29; 'array': 0.29; 'that.': 0.30; 'fri,': 0.31; 'received:(smtp server)': 0.31; "can't": 0.32; 'structure': 0.32; 'another': 0.34; 'subject:?': 0.34; 'to:addr:python-list': 0.35; 'according': 0.36; 'but': 0.36; 'two': 0.37; 'subject:: ': 0.37; 'thought': 0.37; 'ok,': 0.37; 'rather': 0.38; 'method': 0.39; 'to:addr:python.org': 0.39; 'seem': 0.39; 'received:192': 0.39; 'data': 0.40; 'some': 0.40; 'your': 0.60; 'different': 0.64; 'charset:windows-1252': 0.65; 'herron': 0.84; 'subject:here': 0.84; 'todd': 0.84; 'behaviors.': 0.91
X-Sender-Id gary.herron@islandtraining.com
Date Fri, 05 Jun 2015 06:23:53 -0700
From Gary Herron <gary.herron@islandtraining.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
MIME-Version 1.0
To python-list@python.org
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>
In-Reply-To <pan.2015.06.05.13.11.13@nowhere.invalid>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Mailman-Approved-At Fri, 05 Jun 2015 15:35:35 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.199.1433511337.13271.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433511337 news.xs4all.nl 2891 [2001:888:2000:d::a6]:52549
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92146

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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