-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], ...].

1

1 Answer 1

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})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.