anybody can help with the way how to sort my numbers in different categories:

```
3.83
3.93
3.48
2.96
3.66
2.79
3.17
```

I want to find the way how to return the number of appearances, something like:

```
1.5-2: 0
2-2.5: 0
2.5-3.2: 3
3.2-4: 4
```

Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.

Sign up to join this community
Anybody can ask a question

Anybody can answer

The best answers are voted up and rise to the top

What you are describing is a histogram binning problem. In python, you can use the numpy `histogram`

function, ex.:

```
>>> import numpy as np
>>> print np.histogram([3.83,3.93,3.48,2.96,3.66,2.79,3.17],[2,2.5,3.2,4])
(array([0, 3, 4]), array([ 2. , 2.5, 3.2, 4. ]))
>>>
```

Documentation:

Using the `histogram.py`

util, which includes an option for binning numbers in a custom list of buckets:

```
histogram.py --no-mvsd -m 1.5 -x 4 -B 2,2.5,3.2,4 < numbers.txt
```

Output:

```
# NumSamples = 7; Min = 1.50; Max = 4.00
# each ∎ represents a count of 1
1.5000 - 2.0000 [ 0]:
2.0000 - 2.5000 [ 0]:
2.5000 - 3.2000 [ 3]: ∎∎∎
3.2000 - 4.0000 [ 4]: ∎∎∎∎
```

Note: the current version (*v0.3.1*) of the above util is a bit temperamental. One might suppose `histogram.py --no-mvsd -B 1.5,2,2.5,3.2,4 < numbers.txt`

would be sufficient, but the resulting output then omits the `0`

count rows, printing only the two rows with `3`

and `4`

. Adding a *min* `-m 1.5`

and *max* `-x 4`

, plus paring the `-B`

list are needed to produce the desired output.

histogram binningproblem. See for example numpy.histogram