0

I have an array of integers representing class label:

y = np.array([0,1,0,2,3,4,1,3,2,4])

I want replace elements 0, 1 with class name "stopped" and elements 2,3,4 with class name "moving".

class_mapping = {"stopped": [0, 1], "moving": [2,3,4]}
label = y.map(class_mapping)
AttributeError: 'numpy.ndarray' object has no attribute 'map'

Required output:

label = ["stopped", "stopped", "stopped", "moving", "moving", "moving", "stopped", "moving", "moving", "moving"]
Amina Umar
  • 502
  • 1
  • 9
  • Just rework your dictionary using `d = {k: v for v, l in class_mapping.items() for k in l}` and use that to map with the linked answer – mozway Feb 23 '23 at 13:30

0 Answers0