[Numpy-discussion] numpy.genfromtxt converters issue

Damien Moore damienlmoore@gmail....
Sat Nov 6 10:52:11 CDT 2010


In reply to my own question, the trivial, but massively inefficient solution
is:

s=StringIO.StringIO('q1,2\nq3,4')
a=numpy.genfromtxt(s,delimiter=',',converters={0:lambda s:float(s[1:])})
a1 = numpy.array(a.tolist())

But what I really want to do is have genfromtxt do the conversion for me.
Specifically, if I specify a dtype like:

a=numpy.genfromtxt(s,delimiter=',',dtype=float,converters={0:lambda
s:float(s[1:])})

then, ideally from my perspective, genfromtxt should coerce values to the
dtype choice (after the converter has done its work) and output a 2d array
or report an error. Instead it seems like whenever a converter is used,
dtype gets ignored and a 1d array of tuples is always returned.

More generally, it seems like the caller should have more control over what
genfromtxt returns, whether a 1d array of tuples or the 2d array of a
specific type.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20101106/2c78c272/attachment.html 


More information about the NumPy-Discussion mailing list