[Numpy-discussion] using numpy.savetxt to save columns of numerical values and columns of text values

Richared Beare richard.beare@sci.monash.edu...
Thu Nov 26 23:30:07 CST 2009


I have been unable to find a way of doing a very simple thing: saving 
data that contains both arrays of numerical values and arrays of string 
values, using savetxt in numpy.

As a very simple example, suppose a is a numpy array of integers and b 
is one containing strings, e.g.:

    a = np.array([1,2,3])

    b = np.array(['one', 'two', 'three'])

The following call to savetxt:

    savetxt('test.txt', transpose((a,b)), fmt='%i %s')

produces the following error:

    float argument required, not numpy.string_

I don't have any problems if I mix integers and floats in the format 
string, or save all values as strings, but I am completely unable to 
save formatted numerical values and strings in different columns using 
savetxt.

There must be an easy solution!

Thank you. 

Richard Beare


More information about the NumPy-Discussion mailing list