import numpy as np
A = np.array([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 20]) counter = np.bincount(A)
counter
array([0, 2, 1, 2, 1, 3, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], dtype=int64)
[(i,counter[i]) for i in range(21)]
[(0, 0), (1, 2), (2, 1), (3, 2), (4, 1), (5, 3), (6, 1), (7, 0), (8, 0), (9, 1), (10, 0), (11, 0), (12, 0), (13, 0), (14, 0), (15, 0), (16, 0), (17, 0), (18, 0), (19, 0), (20, 1)]