docarray.math.helper module#
- docarray.math.helper.minmax_normalize(x, t_range=(0, 1), x_range=None, eps=1e-07)[source]#
Normalize values in x into t_range.
x can be a 1D array or a 2D array. When x is a 2D array, then normalization is row-based.
Note
with t_range=(0, 1) will normalize the min-value of the data to 0, max to 1;
with t_range=(1, 0) will normalize the min-value of the data to 1, max value of the data to 0.
- Parameters:
x (
ndarray
) – the data to be normalizedt_range (
Tuple
) – a tuple represents the target range.x_range (
Optional
[Tuple
]) – a tuple represents x range.eps (
float
) – a small jitter to avoid divde by zero
- Returns:
normalized data in t_range
- docarray.math.helper.top_k(values, k, descending=False)[source]#
Finds values and indices of the k largest entries for the last dimension.
- Parameters:
values (
ndarray
) – array of distancesk (
int
) – number of values to retrievedescending (
bool
) – find top k biggest values
- Return type:
Tuple
[ndarray
,ndarray
]- Returns:
indices and distances
- docarray.math.helper.update_rows_x_mat_best(x_mat_best, x_inds_best, x_mat, x_inds, k)[source]#
Updates x_mat_best and x_inds_best rows with the k best values and indices (per row) from x_mat union x_mat_best.
- Parameters:
x_mat (
ndarray
) – numpy array of the first matrixx_inds (
ndarray
) – numpy array of the indices of the first matrixx_mat_best (
ndarray
) – numpy array of the second matrixx_inds_best (
ndarray
) – numpy array of the indices of the second matrixk (
int
) – number of values to retrieve
- Returns:
indices and distances