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


Groups > comp.lang.python > #82530

Re: numpy question (fairly basic, I think)

From Gregory Ewing <greg.ewing@canterbury.ac.nz>
Newsgroups comp.lang.python
Subject Re: numpy question (fairly basic, I think)
Date 2014-12-15 11:26 +1300
Message-ID <cf6h47Fa84uU1@mid.individual.net> (permalink)
References <548cd14c$0$13013$c3e8da3$5496439d@news.astraweb.com> <mailman.16946.1418567821.18130.python-list@python.org>

Show all headers | 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