baybe.searchspace.utils.select_via_flat_index¶
- baybe.searchspace.utils.select_via_flat_index(flat_idx: int, /, groups: Sequence[Sequence[_T]])[source]¶
Select one element per group using a flat Cartesian-product index.
Maps a single integer index over the Cartesian product of
groupsto the corresponding element from each group vianumpy.unravel_index().Examples
>>> groups = [[0, 1], ["a", "b"]] >>> select_via_flat_index(0, groups) [0, 'a'] >>> select_via_flat_index(1, groups) [0, 'b'] >>> select_via_flat_index(2, groups) [1, 'a'] >>> select_via_flat_index(3, groups) [1, 'b']