[Numpy-discussion] Using numpy's flatten_dtype with structured dtypes that have titles
Thu Aug 19 16:07:03 CDT 2010
I originally posted this question on stackoverflow, and the user who
responded to me suggested that I bring this issue to the attention of the
I am working with structured arrays to store experimental data. I'm using
titles to store information about my fields, in this case the units of
measure. When I call numpy.lib.io.flatten_dtype() on my dtype, I get:
ValueError: too many values to unpack
File "c:\Python25\Lib\site-packages\numpy\lib\_iotools.py", line 78,
(typ, _) = ndtype.fields[field]
I wouldn't really care, except that numpy.genfromtxt() calls
numpy.lib.io.flatten_dtype(), and I need to be able to import my data from
I'm wondering if I've done something wrong. Is flatten_dtype() not meant to
support titles? Is there a work-around for genfromtxt()?
Here's a snippet of my code:
fname = "C:\\Somefile.txt"
dtype = numpy.dtype([(("Amps","Current"),"f8"),(("Volts","Voltage"),"f8")])
myarray = numpy.genfromtxt(fname,dtype)
The user who responded suggested the following monkey-patch:
Unpack a structured data-type.
names = ndtype.names
if names is None:
types = 
for field in names:
typ_fields = ndtype.fields[field]
flat_dt = flatten_dtype(typ_fields)
Is this something that could be changed in numpy?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion