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


Groups > comp.lang.python > #82530

Re: numpy question (fairly basic, I think)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Gregory Ewing <greg.ewing@canterbury.ac.nz>
Newsgroups comp.lang.python
Subject Re: numpy question (fairly basic, I think)
Date Mon, 15 Dec 2014 11:26:19 +1300
Lines 32
Message-ID <cf6h47Fa84uU1@mid.individual.net> (permalink)
References <548cd14c$0$13013$c3e8da3$5496439d@news.astraweb.com> <mailman.16946.1418567821.18130.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net /aZlsG1FcOnu71esF1lWjwKW3CK3bPFjkg23MF6lvrQg4KGigR
Cancel-Lock sha1:wXtqtgvdonBGpYJWjBzaNGPSuxQ=
User-Agent Mozilla Thunderbird 1.0.5 (Macintosh/20050711)
X-Accept-Language en-us, en
In-Reply-To <mailman.16946.1418567821.18130.python-list@python.org>
Xref csiph.com comp.lang.python:82530

Show key headers only | View raw


Albert-Jan Roskam wrote:
> I was trying to change the one-dim array into a two-dim array so
> I could easily retrieve columns. I now use a pandas DataFrame to do that.

Numpy can do that, if I understand what you want correctly,
but it requires an unintuitive trick.

The trick is to index the array with the name of a field,
and *only* the name of the field. For example, the following
gives you a slice containing all the values from the 'v02'
fields of your data:

   array['v02']

Note: Indexing with a field name generally seems to follow
a different set of rules. Some things that you'd think would
work don't, e.g.

    array[:, 'v02']

fails with a rather confusing error message. Also,

    array[0, 'v02']

doesn't work either, and has to be written

    array[0]['v02']

instead.

-- 
Greg

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


Thread

numpy question (fairly basic, I think) Albert-Jan Roskam <fomcl@yahoo.com> - 2014-12-13 21:36 +0000
  Re: numpy question (fairly basic, I think) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-14 10:52 +1100
    Re: numpy question (fairly basic, I think) Albert-Jan Roskam <fomcl@yahoo.com> - 2014-12-14 14:31 +0000
      Re: numpy question (fairly basic, I think) Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-12-15 11:26 +1300

csiph-web