Counter numpy array of statistics

1. frequency statistics for elements in the array by counter library.

In [1]: import numpy as np

In [2]: from collections import Counter

In [3]: a = np.array([[1,2],[3,4]])

In [4]: Counter(a.flatten())
Out[4]: Counter({1: 1, 2: 1, 3: 1, 4: 1})

In [5]: b = np.array([[1,1],[3,4]])
In [6]: Counter(b.flatten())
Out[6]: Counter({1:2, 3: 1, 4: 1})

2. References

Published 38 original articles · 98 won praise · views 360 000 +

Guess you like

Origin blog.csdn.net/xijuezhu8128/article/details/88555347