Coverage for src/foapy/characteristics/ma/_volume.py: 100%
3 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-17 20:45 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-17 20:45 +0000
1import numpy as np
4def volume(intervals, dtype=None):
5 """
6 Calculates volumes of the intervals grouped by congeneric sequence.
8 $$
9 \\left[ V_j \\right]_{1 \\le j \\le m} =
10 \\left[
11 \\prod_{i=1}^{n_j} \\Delta_{ij}
12 \\right]_{1 \\le j \\le m}
13 $$
15 where \\( \\Delta_{ij} \\) represents $i$-th interval of $j$-th
16 congeneric intervals array, \\( n_j \\) is the total
17 number of intervals in $j$-th congeneric intervals array
18 and $m$ is number of congeneric intervals arrays.
20 Parameters
21 ----------
22 intervals : array_like
23 An array of congeneric intervals array
24 dtype : dtype, optional
25 The dtype of the output
27 Returns
28 -------
29 : array
30 An array of the volumes of congeneric intervals.
32 Examples
33 --------
35 Calculate the volumes of a sequence.
37 ``` py linenums="1"
38 import foapy
39 import numpy as np
41 source = np.array(['a', 'b', 'a', 'c', 'a', 'd'])
42 order = foapy.ma.order(source)
43 intervals = foapy.ma.intervals(order, foapy.binding.start, foapy.mode.normal)
44 result = foapy.characteristics.ma.volume(intervals)
45 print(result)
46 # [4 2 4 6]
47 ```
49 Calculate the volumes of congeneric intervals of a sequence.
51 ``` py linenums="1"
52 import foapy
54 X = []
55 X.append([1, 1, 4, 4])
56 X.append([3, 1, 3])
57 X.append([5, 3, 1])
59 result = foapy.characteristics.ma.volume(X)
60 print(result)
61 # [16 9 15]
62 ```
63 """ # noqa: W605
65 return np.asanyarray([np.prod(line, dtype=dtype) for line in intervals])