I'm having a problem sorting a numpy array that has numbers as strings. I need to keep these as strings because there are other words after the integers.
It's sorting negative numbers in reverse order:
>>> import numpy as np
>>> a = np.array(["3", "-2", "-1", "0", "2"])
>>> a.sort()
>>> a
array(['-1', '-2', '0', '2', '3'], dtype='|S2')
I would have expected the output to be:
array(['-2', '-1', '0', '2', '3'], dtype='|S2')
Any suggestions?
numpy
. – Steven Rumbalski Oct 3 '11 at 18:05"76 trombones"
, and you want to treat it like the number76
followed by the word"trombones"
? Then do that. Parse the strings and create 2-tuples of (number, rest of string). – Karl Knechtel Oct 4 '11 at 0:11