Coverage for src/foapy/core/_intervals_distribution.py: 100%
7 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-17 19:57 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-17 19:57 +0000
1import numpy as np
2from numpy import ndarray
5def intervals_distribution(tuple_result) -> ndarray:
6 """
7 Compute the frequency distribution of interval values.
9 Given the output of :func:`intervals_tuple` (or any 1-D array of strictly
10 positive integers), counts how many times each interval value occurs.
11 The result is a 1-D array of length ``max(tuple_result)`` where
12 ``result[i]`` is the count of interval value ``i + 1``.
14 Parameters
15 ----------
16 tuple_result : array_like
17 1-D array of strictly positive integers, typically produced by
18 :func:`intervals_tuple`.
20 Returns
21 -------
22 ndarray
23 1-D integer array of length ``max(tuple_result)`` (or empty for
24 empty input). ``result[i]`` equals the number of elements in
25 *tuple_result* with value ``i + 1``.
27 Examples
28 --------
30 ``` py linenums="1"
31 import numpy as np
32 from foapy.core import intervals_distribution
34 print(intervals_distribution(np.array([1, 2, 2, 4, 2])))
35 # [1 3 0 1]
37 print(intervals_distribution(np.array([])))
38 # []
39 ```
40 """
41 ar = np.asanyarray(tuple_result, dtype=np.intp)
43 if ar.size == 0:
44 return np.array([], dtype=np.intp)
46 return np.bincount(ar - 1).astype(np.intp)