chanley at stsci.edu
Fri Dec 9 07:16:30 CST 2005
Thanks, this is what I needed to get started.
> -----Original Message-----
> From: scipy-dev-bounces at scipy.net [mailto:scipy-dev-bounces at scipy.net] On
> Behalf Of Travis Oliphant
> Sent: Thursday, December 08, 2005 5:59 PM
> To: Christopher Hanley
> Cc: SciPy Developers List
> Subject: Re: [SciPy-dev] examples
> There is no fromarrays function yet, so there is no records.array
> function yet.
> It should be a straightforward matter to create one (you shouldn't have
> to distinguish between chararrays and other arrays though).
> In this case say x is the list of tuples.
> r = ndrecarray(len(x), formats= 'u1,f4,S1')
> for ind, val in enumerate(x):
> for k in range(len(val)):
> r[ind]['f%d' %(k+1)] = val[k]
> should do it (get recent SVN, there was a bug in setitem that prevented
> this from working before).
> Then (on my system):
> >>> r
> ndrecarray([[1, 11.0, 'a'], [2, 22.0, 'b'], [3, 33.0, 'c'], [4, 44.0,
> [5, 55.0, 'e'], [6, 66.0, 'f'], [7, 77.0, 'g']], dtype=record6)
> >>> r.f1
> ndrecarray([1, 2, 3, 4, 5, 6, 7], dtype=uint8)
> >>> r.f2
> ndrecarray([ 11., 22., 33., 44., 55., 66., 77.], dtype=float32)
> >>> r.f3
> ndrecarray([a, b, c, d, e, f, g], dtype=string1)
> Obviously a fromarray function is needed to make this process easier.
> This function would need to be a bit more general to handle
> multidimensional cases and arbitrary field names.
> The format string does not allow an easy way to right nested records,
> but the general ndrecarray allows it. The infrastructure for making it
> easy to deal with nested records is there but the user-convenience may
> not be.
> I would love your help on the fromarray, fromstring, and friends
More information about the Scipy-dev