[SciPy-user] io.read_array with strings

Charles-Antoine Robelin car@melix....
Thu Feb 22 12:51:21 CST 2007


I have been using io.read_array successfully to read ASCII 
files containing integers and floats, and I would like to 
import strings into arrays as well.

I tried with io.read_array, but did not get it to work:
If I create an array manually (i.e., numpy.array([['a1', 
'd3', 'gg'],['wq', 'ty', 'e']])), the type (dtype) of its 
elements is '|S4', so I suspect numpy.arrays can handle 
strings.

However, io.read_array(<filename>, separator=',') on the 
following file:
a1, d3, gg
wq, ty, e
returns an array of floats with the correct shape, 
containing the numbers it could find (a1 -> 1.; d3 -> 3.) 
and 0. where no number could be found.
I could not find how to force the type "strings," such as 
atype='<strings>' in the call of read_array.

Is importing strings possible with io.read_array, or with 
another function, without having to parse manually?

Thanks in advance.


More information about the SciPy-user mailing list