ARTICLE AD BOX
I am trying to use numpy sort for numpy string array. But, when I try to print them element-wise with string print format specifier '{:s}' it is giving me the following error.
print("{0:s} {1:2d}".format(lth_str[j],lth_arr[j])) ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ TypeError: unsupported format string passed to numpy.ndarray.__format__I don't understand this. Why is this happening and how can I work around this issue? Am I missing something? Data-type mismatch maybe?
The following is the code.
import numpy as np arr = np.array([ [0,19,20,39], [1,18,21,38], [2,17,22,37], [3,16,23,36], [9,15,24,35], [8,14,25,34], [7,13,26,33], [6,12,27,32], [5,11,28,31], [4,10,29,30], ]) starr = np.array(["a","b","c","d","e","f","g","h","i","j"]) for i in range(4): lth_idx = np.argsort(arr[:,i]) lth_arr = arr[lth_idx] lth_str = starr[lth_idx] for j in range(10): print("{0:s} {1:2d}".format(lth_str[j],lth_arr[j])) print("=====================")