np.bincount 使用例

In [1]:
import numpy as np
In [2]:
A = np.array([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 20])
counter = np.bincount(A)
In [3]:
counter
Out[3]:
array([0, 2, 1, 2, 1, 3, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
      dtype=int64)
In [4]:
[(i,counter[i]) for i in range(21)]
Out[4]:
[(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)]