I have an array of tokens, and each token corresponds to a different class from 1 to n. I need to balance the tokens array/list so that there are an equal number of tokens for each class. I want to do this by removing the elements of tokens.
In the example below the class with the lowest number of tokens is class 2 which has only 2 tokens. So I want to remove elements from other classes until their count is also 2.
e.g.
tokens = array(['a','b','c','d','e','f','g','h','l'])
classes = array([ 1 , 1 , 1 , 1 , 2 , 2 , 3 , 3 , 3])
In this example, the classes are listed in ascending order (for clarity of task) but in reality, the classes are in no particular order.
e.g.
sol = array(['c','d','e','f','g','h'])
or
sol = array(['a','b','e','f','g','h'])
etc.
Obviously because you have a choice of elements to remove in an excess class, you can have different solutions (like above). I need a function that can take the tokens and classes and output a sol.