Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 3
    What if I want to access the number of occurences of each unique elements of the array without assigning to the variable - counts. Any hints on that ? Commented Dec 24, 2016 at 23:08
  • 1
    I have the same goal as @sajis997. I want to use 'count' as an aggregating function in a groupby Commented Mar 15, 2018 at 16:34
  • 9
    this is a hack. Numpy has functions for this called bincount() or histogram() Commented Oct 22, 2018 at 3:01
  • 7
    Tried using both methods for a very large array (~30Gb). Numpy method ran out of memory whereas the collections.Counter worked just fine Commented Nov 26, 2019 at 13:10
  • 2
    For those wondering, this answer works for any type of np array (e.g. it works for floats), unlike some of the answers provided. Commented Aug 10, 2021 at 10:27