docarray.math.distance package#
Submodules#
Module contents#
- docarray.math.distance.pdist(x_mat, metric)[source]#
Computes Pairwise distances between observations in n-dimensional space.
- Parameters:
x_mat (ArrayType) – Union[‘np.ndarray’,’scipy.sparse.csr_matrix’, ‘scipy.sparse.coo_matrix’] of ndim 2
metric (
str
) – string describing the metric type
- Return type:
np.ndarray
- Returns:
np.ndarray of ndim 2
- docarray.math.distance.cdist(x_mat, y_mat, metric, device='cpu')[source]#
Computes the pairwise distance between each row of X and each row on Y according to metric. - Let n_x = x_mat.shape[0] - Let n_y = y_mat.shape[0] - Returns a matrix dist of shape (n_x, n_y) with dist[i,j] = metric(x_mat[i], y_mat[j]). :type x_mat: ArrayType :param x_mat: numpy or scipy array of ndim 2 :type y_mat: ArrayType :param y_mat: numpy or scipy array of ndim 2 :type metric:
str
:param metric: string describing the metric type :type device:str
:param device: the computational device, can be either cpu or cuda. :rtype: np.ndarray :return: np.ndarray of ndim 2