[Numpy-discussion] Using loadtxt to read in mixed data types
Fri Jul 3 03:30:59 CDT 2009
Pierre GM <pgmdevlist <at> gmail.com> writes:
> What about
> 'formats':[eval(b) for b in event_format]
> Should it fail, try something like:
> dtype([(x,eval(b)) for (x,b) in zip(event_fields, event_format)])
> At least you force dtype to have the same nb of names & formats.
You could use
data = np.genfromtxt(filename, names=listofname, dtype=None)
Then you just need to specify the column names, and not the dtypes (they are
inferred from the data). There are probably backwards compatibility issues, but
it would be great if dtype=None was the default for genfromtxt.
More information about the Numpy-discussion