I have a question regarding Numpy arrays (the answer should include them). I want to create and array where each element will be mapped into a specific integer. Here is the code I got until now:
array1 = np.array(['dog', 'cat', 'parrot', 'parrot', 'dog'])
array2 = (np.unique(array1))
for index, key in enumerate(array2):
print(np.where(array1 == key, index+1, 0))
The output now is:
[1 0 0 0 1]
[0 2 0 0 0]
[0 0 3 3 0]
But I want it to be just
[1 2 3 3 1]