Last active
May 20, 2018 15:32
-
-
Save yuchen-xue/55e350d5d31d59bbb8412b938ba66dd5 to your computer and use it in GitHub Desktop.
Count the occurrence of certain item in an ndarray in Python. Ref: https://stackoverflow.com/a/28663910/8809592
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
a = np.array([0, 3, 0, 1, 0, 1, 2, 1, 0, 0, 0, 0, 1, 3, 4]) | |
unique, counts = numpy.unique(a, return_counts=True) | |
print(dict(zip(unique, counts))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment