Home > Net >  How to covert labels array into one vector of letters
How to covert labels array into one vector of letters

Time:05-08

I have the labels as the following: array([[1., 0., 0., 0.], [1., 0., 0., 0.], [1., 0., 0., 0.], ..., [1., 0., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]], dtype=float32)

How can I turn this into one vector that has for example a letter representing each class [a, a, a, b, c, d]

CodePudding user response:

You can use np.argmax() with map():

list(map(lambda x: chr(ord('a')   x), np.argmax(arr, axis=1)))

This outputs:

['a', 'a', 'a', 'a', 'c', 'd']
  • Related