hyperfine.utilities.sampling_index
- hyperfine.utilities.sampling_index(array: Sequence[T], n_elements: int, begin_offset: int = 0, end_offset: int = 0) Sequence[T][source]
Sample evenly spaced indices from an array.
Inspired by: https://stackoverflow.com/a/50685454
- Parameters:
array – The array to sample indices from.
n_elements – Number of indices to select.
begin_offset – Offset from
array’s beginning index when sampling.end_offset – Offset from
array’s ending index when sampling.
- Returns:
An array of the sampled indices.
Example
import numpy as np from hyperfine.utilities import sampling_index a = np.linspace(0.0, 30.0, 100) n_elem = 5, beg_off = 0 end_off = 0 idx = sampling_index(a, n_elem, beg_off, end_off)