Skip to content

Instantly share code, notes, and snippets.

@austinbrian
Created August 15, 2018 14:49
Show Gist options
  • Save austinbrian/eef460eeecbc675f9c3cefb482e8e98d to your computer and use it in GitHub Desktop.
Save austinbrian/eef460eeecbc675f9c3cefb482e8e98d to your computer and use it in GitHub Desktop.
Quick summary of numpy counts into dict
a = numpy.array([0, 3, 0, 1, 0, 1, 2, 1, 0, 0, 0, 0, 1, 3, 4])
unique, counts = numpy.unique(a, return_counts=True)
dict(zip(unique, counts)) # returns {0: 7, 1: 4, 2: 1, 3: 2, 4: 1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment