From: Travis O. <oli...@ie...> - 2006-10-29 00:07:20
|
Pierre GM wrote: > Folks, > What is the easiest way to define a recarray of arrays ? > For example, I'd need something like that: > Given three arrays > >>>> x = N.arange(5) >>>> y = x+1 >>>> z = N.sqrt(x) >>>> > and a list of names: > >>>> n = ['x','y','z'] >>>> > Define a 3-record array with two fields: the first one being a ndarray (in x, > y or), the second a string (in n). > > I'm a bit at loss with the definition of the corresponding dtype... > I'm a little unclear one what you want. Here is a data-type whose first field is a name and whose second field is a 5-element array: dt = N.dtype([('name', 'S10'), ('data', float, (5,))]) Then: a = array([('x',x),('y',y),('z',z)],dt) gives array([('x', [0.0, 1.0, 2.0, 3.0, 4.0]), ('y', [1.0, 2.0, 3.0, 4.0, 5.0]), ('z', [0.0, 1.0, 1.4142135623730951, 1.7320508075688772, 2.0])], dtype=[('name', '|S10'), ('data', '<f8', (5,))]) -Travis |