[Numpy-discussion] array with named columns (or record arrays with homogenous types)
Mon Sep 22 23:06:14 CDT 2008
> Message: 8
> Date: Mon, 22 Sep 2008 19:28:50 -0400
> From: Pierre GM <email@example.com>
> Subject: Re: [Numpy-discussion] array with named columns (or record
> arrays with homogenous types)
> To: Discussion of Numerical Python <firstname.lastname@example.org>
> Message-ID: <email@example.com>
> Content-Type: text/plain; charset="iso-8859-1"
> On Monday 22 September 2008 19:25:16 Tony S Yu wrote:
>>>>> import numpy as np
>>>>> color = np.array([(1, 2, 3), (4, 5, 6)],
>> ... dtype=[('r', '<f4'), ('g', '<f4'), ('b',
>> # get the average (grayscale) of the first row
> What about
> color.view((float,3)).mean() ?
Yeah, that works perfectly; by specifying the axis and dropping the
index (`color.view(('<f4',3)).mean(axis=1)) gives the mean of all the
BTW, is the tuple argument you use with `view` documented anywhere; I
haven't seen it before and a quick search doesn't give any results.
More information about the Numpy-discussion