-1

I have a numpy array of samples, [0, 0, 2.5, -5.0, ...]. In my case all samples are multiples of 2.5. I want tot know how many times each sample occurs. More or less like numpy.hist. In this case something like: [[-5.0, 1], [0, 2], [2.5, 1], ...].

  • @:Just check here ..http://stackoverflow.com/questions/10741346/numpy-frequency-counts-for-unique-values-in-an-array – George Apr 02 '15 at 13:25

1 Answers1

0

You can use

[[x,l.count(x)] for x in set(l)]

Output

[[0, 2], [2.5, 1], [-5.0, 1]]

You can also use counter

>>> l = [0,0,2.5,-5.0]
>>> from collections import Counter
>>> Counter(l)
Counter({0: 2, 2.5: 1, -5.0: 1})
avinash pandey
  • 1,321
  • 2
  • 11
  • 15