watex.utils.random_selector#
- watex.utils.random_selector(arr, /, value, seed=None, shuffle=False)[source]#
Randomly select the number of values in array.
- Parameters:
arr (ArrayLike) – Array of values
value (float, arraylike) – If
floatvalue is passed, it indicates the number of values to select among the length of ar. Ifarrayis passed, it should be self contain in the given array. However ifstringis given and contain the%, it calculates the ratio of number to randomly selected.see (int, Optional) – Allow retrieving the identical value randomly selected in the given array.
suffle (bool, False) – If
True, shuffled the selected values.
- Returns:
arr
- Return type:
Array containing the selected values
Examples
>>> import numpy as np >>> from watex.utils.funcutils import random_selector >>> dat= np.arange (42 ) >>> random_selector (dat , 7, seed = 42 ) array([0, 1, 2, 3, 4, 5, 6]) >>> random_selector ( dat, ( 23, 13 , 7)) array([ 7, 13, 23]) >>> random_selector ( dat , "7%", seed =42 ) array([0, 1]) >>> random_selector ( dat , "70%", seed =42 , shuffle =True ) array([ 0, 5, 20, 25, 13, 7, 22, 10, 12, 27, 23, 21, 16, 3, 1, 17, 8, 6, 4, 2, 19, 11, 18, 24, 14, 15, 9, 28, 26])