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


Groups > comp.lang.python > #44103

Re: Lists and arrays

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.041
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'example:': 0.03; 'assign': 0.07; 'error:': 0.07; 'float': 0.07; 'operand': 0.09; 'referenced': 0.09; 'type,': 0.09; 'python': 0.11; "wouldn't": 0.14; 'before.': 0.16; 'brackets.': 0.16; 'did,': 0.16; 'mylist': 0.16; 'numpy': 0.16; 'received:74.208.4.195': 0.16; 'subscripted': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'later': 0.20; 'header:User-Agent:1': 0.23; "aren't": 0.24; 'integer': 0.24; 'help!': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'array': 0.29; 'list:': 0.30; "skip:' 10": 0.31; 'that.': 0.31; 'apparently': 0.31; 'probably': 0.32; 'could': 0.34; 'convert': 0.35; 'but': 0.35; 'really': 0.36; 'method': 0.36; 'wrong': 0.37; 'list': 0.37; 'list.': 0.37; 'lists.': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'that,': 0.38; 'anything': 0.39; 'help,': 0.39; 'itself': 0.39; 'to:addr:python.org': 0.39; 'above,': 0.60; 'numbers': 0.61; 'simple': 0.61; "you're": 0.61; "you'll": 0.62; 'making': 0.63; 'show': 0.63; 'name': 0.63; 'kind': 0.63; 'pick': 0.64; 'more': 0.64; 'different': 0.65; 'here': 0.66; 'received:74.208': 0.68; 'gotten': 0.74; 'square': 0.74; 'ana': 0.84; 'presumably': 0.84; 'tricky': 0.84; 'type(s)': 0.84; 'want:': 0.84; 'subject:Lists': 0.91
Date Mon, 22 Apr 2013 14:34:42 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4
MIME-Version 1.0
To python-list@python.org
Subject Re: Lists and arrays
References <de1cc79e-cbf7-4b0b-ae8e-18841a1ef095@googlegroups.com>
In-Reply-To <de1cc79e-cbf7-4b0b-ae8e-18841a1ef095@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 8bit
X-Provags-ID V02:K0:VsuttVbRAeP6/C536xoZ5AHzBao0TXauPD1Igqr3X2z Tg4nhb4n7fdLzEQz/snKzyihRXP80jO5wjcM5UZIviU4xpWq0p 1KmNg8k+2aPeIHPOneiaaDb6d9nsj84u2F522YrrlxTwWXJW3A zMaxu4UIp/kioBQBKFQ2v1j69mbRG1Zx5TMFjClFBr+8fff9wB S7Qc87I5iT3cjhohwvzr5bX9eG16UG+kFapGb5fCJJvjyFQtY7 S503pSAyYw3GqR9pCimNVQVlWayxhWRiQhb/Z6kR9qPNnwQ/c0 1hDMuvZjdvHTT/IHGUdUTssxGsNd0xz23ZDe+LoPxp3aN3B3A= =
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.934.1366655702.3114.python-list@python.org> (permalink)
Lines 63
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1366655702 news.xs4all.nl 2261 [2001:888:2000:d::a6]:34249
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:44103

Show key headers only | View raw


On 04/22/2013 02:13 PM, Ana Dionísio wrote:
> Hello!
>
> I need your help!
>
> I have an array

I think you mean you have a numpy array, which is very different than a 
python array.array


> and I need pick some data from that array and put it in a list, for example:
>
> array= [a,b,c,1,2,3]

That's a list.

>
> list=array[0]+ array[3]+ array[4]

Nothing wrong with that, other than that you just hid the name of the 
list type, making it tricky to later convert things to lists.

>
> list: [a,1,2]

You'll never get that.  When you assign an object to a list, the object 
itself is referenced in that list, not the name that it happened to have 
before.  So if a was an object of type float and value 41.5, then you 
presumably want:
    mylist: [41.5, 1, 2]


>
> When I do it like this: list=array[0]+ array[3]+ array[4] I get an error:
>
> "TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'numpy.ndarray'"
>

Apparently you did not use the line
     array= [a,b,c,1,2,3]

as you said above, but some other assignment, perhaps using a numpy 
method or six.  Worse, apparently the elements of that collection aren't 
simple numbers but some kind of numpy thingies as well.

If you show what you actually did, probably someone here can help, 
though the more numpy you use, the less likely that it'll be me.


If you really had a list, you wouldn't have gotten an error, but neither 
would you have gotten anything like you're asking.  array[3] + array[4] 
== 1+2 == 3.  If you're trying to make a list using + from a subscripted 
list, you'd have to enclose each integer in square brackets.

mylist = [array[0]] + [array[3]] + [array[4]]

Alternatively, you could just do

mylist = [ array[0], array[3], array[4] ]

-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Lists and arrays Ana Dionísio <anadionisio257@gmail.com> - 2013-04-22 11:13 -0700
  Re: Lists and arrays Dave Angel <davea@davea.name> - 2013-04-22 14:34 -0400
  Re: Lists and arrays "BartC" <bc@freeuk.com> - 2013-04-22 22:24 +0100
  Re: Lists and arrays 88888 Dihedral <dihedral88888@googlemail.com> - 2013-04-23 00:50 -0700
  Re: Lists and arrays Denis McMahon <denismfmcmahon@gmail.com> - 2013-04-23 19:30 +0000

csiph-web