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 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: References: <548cd14c$0$13013$c3e8da3$5496439d@news.astraweb.com> 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: Xref: csiph.com comp.lang.python:82530 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