NumPy array/matrix of mixed types

Your problem is in the data. Try this:

res = np.array(("TEXT", 1, 1), dtype="|S4, i4, i4")

or

res = np.array([("TEXT", 1, 1), ("XXX", 2, 2)], dtype="|S4, i4, i4")

The data has to be a tuple or a list of tuples. Not quite evident form the error message, is it?

Also, please note that the length of the text field has to be specified for the text data to really be saved. If you want to save the text as objects (only references in the array, then:

res = np.array([("TEXT", 1, 1), ("XXX", 2, 2)], dtype="object, i4, i4")

This is often quite useful, as well.

Leave a Comment