[Numpy-discussion] `missing` argument in genfromtxt only a string?
Pierre GM
pgmdevlist@gmail....
Tue Sep 15 12:56:08 CDT 2009
On Sep 15, 2009, at 10:44 AM, Skipper Seabold wrote:
>>>> How do you specify different dtypes in genfromtxt?
>> I could not see the information in the docstring and the dtype
>> argument
>> does not appear to allow multiple dtypes.
Just give a regular dtype, or something that could be interpreted as
such. Have a look at
http://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.html
> # a few incorrect ones
>
> s = StringIO("11.3abcde")
> data = np.genfromtxt(s, dtype=np.dtype(int, float, str), delimiter=
> [1,3,5])
Non-legit at all, but a good idea in that case.
>
> # one I expected to work but have probably made an obvious mistake
>
> s.seek(0)
> data = np.genfromtxt(s, dtype=np.dtype('i8','f8','a5'),
> names=['myint','myfloat','mystring'], delimiter=[1,3,5])
But this one works:
data=np.genfromtxt(s, dtype=np.dtype("i8,f8,a5"), names=
['myint','myfloat','mystring'], delimiter=[1,3,5])
>
> Btw, you don't have to pass it as a dtype. It just needs to be able
> to pass
>
> if dtype is not None:
> dtype = np.dtype(dtype)
>
> I would like to see something like this, as it does when dtype is
> None, but then we would have to have a type argument, maybe rather
> than a dtype argument.
'k. Gonna see what I can do.
> Again, while I'm on it...I noticed the argument to specify the
> autostrip argument that can be provided to _iotools.LineSplitter is
> always False. If this does, what I think (no time to test yet), it
> might be nice to be able to specify this in genfromtxt.
Would you mind giving me an example of usage with the corresponding
expected output, so that I can work on it ?
More information about the NumPy-Discussion
mailing list