0

I'm trying to do the following thing: I have a list:

classes = [0,1,2,3,4,5,6,7,8,9]

I have another list:

labels = [1,1,1,5,3]

I would like to create a list which contains 10 lists within it, so that list number i contains indicators whether the elements in the labels list are equal to class i. For this example:

[[0,0,0,0,0],
 [1,1,1,0,0],
 [0,0,0,0,0],
 [0,0,0,0,1],
 [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]]

I tried the following code:

mappers = [np.vectorize(lambda x : 1 if x==c else 0) for c in classes]
indicators = [mapper(labels) for mapper in mappers]

However, I don't get what I want and I would like your help in this one. I get:

[[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,0,0],
 [0,0,0,0,0],
 [0,0,0,0,0],
 [0,0,0,0,0],
 [0,0,0,0,0]]
ekosman
  • 300
  • 2
  • 13

0 Answers0