mrdja.sampling.sampling_np_array_elements
- mrdja.sampling.sampling_np_array_elements(elements: ndarray, num_samplings: int = 1, replacement: bool = False, len_elements: int | None = None, seed: int | None = None) ndarray[source]
Sample elements from a numpy array.
- Parameters:
elements (np.ndarray) – The array of elements to sample from.
num_samplings (int) – The number of elements to sample. Default is 1.
replacement (bool) – Whether to sample with replacement or not. Default is False.
len_elements (int) – The length of the elements array. Default is None.
seed (int) – The seed value for the random number generator. Default is None.
- Returns:
The sampled elements.
- Return type:
np.ndarray
Examples
>>> import numpy as np >>> import mrdja.sampling as sampling >>> sampling.sampling_np_array_elements(np.array([1,2,3,4,5]), 3, False, seed=42) array([2, 5, 3]) >>> sampling.sampling_np_array_elements(np.array([(1,2),(3,4),(5,6),(7,8),(9,10)]), 3, False, seed=42) array([[ 3, 4], [ 9, 10], [ 5, 6]])