Skip to content

Instantly share code, notes, and snippets.

@vegarsti
Last active May 3, 2019 01:06
Show Gist options
  • Save vegarsti/8ab8a76e17d52580a4f97f0f388e015c to your computer and use it in GitHub Desktop.
Save vegarsti/8ab8a76e17d52580a4f97f0f388e015c to your computer and use it in GitHub Desktop.

Given array a, count occurrences and stack.

e.g. a = np.array([0, 0, 1, 1, 2, 1, 0, 2, 3, 0, 1])

then counts = np.dstack(np.unique(a, return_counts=True)) gives

array([[[0, 4],
        [1, 4],
        [2, 2],
        [3, 1]]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment