[Numpy-discussion] loadtxt

Stéfan van der Walt stefan@sun.ac...
Thu Oct 2 04:15:46 CDT 2008


2008/10/2 Francesc Alted <faltet@pytables.org>:
>> how can I load ASCII data if the file contains characters
>> instead of floats
>
> You would need to specify the length of your strings.  Try with
> dtype="SN", where N is the expected length of the strings.

Other options include:

- using converters to convert the character to a value:

  np.loadtxt('/tmp/bleh.dat', converters={2: lambda x: 0})

- Skipping the specified column:

  np.loadtxt('/tmp/bleh.dat', usecols=(0,1))

Cheers
Stéfan


More information about the Numpy-discussion mailing list