[Numpy-discussion] loadtxt issues

A B python6009@gmail....
Tue Feb 10 23:40:35 CST 2009


How do I write a loadtxt command to read in the following file and
store each data point as the appropriate data type:


Do the strings have to be read in separately from the numbers?

Why would anyone use 'S10' instead of 'string'?

dt = {'names': ('gender','age','weight','bal'), 'formats': ('i4',
'S4','f4', 'f4')}

a = loadtxt("sample_data.txt", dtype=dt)


ValueError: need more than 1 value to unpack

I can do a = loadtxt("sample_data.txt", dtype="string") but can't use
'string' instead of S4 and all my data is read into strings.

Seems like all the examples on-line use either numeric or textual
input, but not both.


More information about the Numpy-discussion mailing list