If I have an array, a = [1,2,3,4,2,1], how can I create another array, which shows the number of times each number in array a has been repeated, for example from array a then the new array would be b = [2,2,1,1]? Is this possible using a command in the NumPy library?
-
Duplicate of stackoverflow.com/q/2600191/929999Torxed– Torxed2020-06-16 12:47:18 +00:00Commented Jun 16, 2020 at 12:47
Add a comment
|
2 Answers
In this case you can do this:
[a.count(i + 1) for i in range(max(a))]
More generally, look into collections.Counter.