I have the following numpy array (list of list)
arr2 =np.array([[15, 2, 2, 0, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2,
2, 0, 13, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 15, 2, 2, 0,
2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 0, 13, 2,
2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2],[15, 2, 2, 0, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2,
2, 0, 13, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 15, 2, 2, 0,
2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 0, 13, 2,
2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2]])
and the following dictionary:
dict2={'B-art': 10,
'B-eve': 11,
'B-geo': 6,
'B-gpe': 15,
'B-nat': 12,
'B-org': 5,
'B-per': 16,
'B-tim': 4,
'I-art': 1,
'I-eve': 0,
'I-geo': 13,
'I-gpe': 7,
'I-nat': 9,
'I-org': 8,
'I-per': 14,
'I-tim': 2,
'O': 3}
My goal is to get a new list with the keys of the dictionary
Expected output:
[['B-gpe', 'I-tim' , 'I-tim', ...]] etc ...
I'm trying the following code:
for key, value in dict2.items():
if value not in arr2:
continue
index = np.where(arr2 == value)
arr2[index] = key
but I'm getting the following error:
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
ValueError: invalid literal for int() with base 10: 'B-gpe'