I've got (what seems to me) a fairly clear-cut example with numpy argsort where it is producing odd results. If I create an example array of characters:
letters = np.array([['b','a','c'],
['c','a','b'],
['b','c','a']]).astype(str)
I'm then looking to sort along the rows (and to retain the sorting sequence, for another use later). The output I get from argsort is
sort_seq = np.argsort(letters, axis=1)
sort_seq
array([[1, 0, 2],
[1, 2, 0],
[2, 0, 1]])
This seems to get the first row right, but not the others. If I use it to reconstruct the array then I get:
output = np.full_like(letters, '')
np.put_along_axis(output, sort_seq, letters,axis=1)
output
which gives
array([['a', 'b', 'c'],
['b', 'c', 'a'],
['c', 'a', 'b']], dtype='<U1')
If I look here and on other sites I can see that argsorting for multi-dimensional arrays has at times not always worked well. But this example seems very close to the one given in the numpy documentation - surely it must work in this case?
Thanks for any assistance!