这就是你已经拥有的:
custom_labels = ['0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111',
'1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111']
output = [[0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]]
你需要得到
1
:
import numpy as np
column = np.argmax(output, axis=1)
Out[10]: array([ 1, 2, 3, 0, 2, 9, 7, 4, 2, 15], dtype=int64)
使用此选项,可以选择相应的自定义标签:
array(['0001', '0010', '0011', '0000', '0010', '1001', '0111', '0100',
'0010', '1111'], dtype='<U4')
但是你想要的是一个列表,但是作为单独的整数:
final_labels = np.array([list(i) for i in np.array(custom_labels)[column]]).astype(int)
array([[0, 0, 0, 1],
[0, 0, 1, 0],
[0, 0, 1, 1],
[0, 0, 0, 0],
[0, 0, 1, 0],
[1, 0, 0, 1],
[0, 1, 1, 1],
[0, 1, 0, 0],
[0, 0, 1, 0],
[1, 1, 1, 1]])