# cdist¶

paddle. cdist ( x, y, p=2.0, compute_mode='use_mm_for_euclid_dist_if_necessary', name=None ) [source]

Compute the p-norm distance between each pair of the two collections of inputs.

This function is equivalent to scipy.spatial.distance.cdist(input,’minkowski’, p=p) if $$p \in (0, \infty)$$. When $$p = 0$$ it is equivalent to scipy.spatial.distance.cdist(input, ‘hamming’) * M. When $$p = \infty$$, the closest scipy function is scipy.spatial.distance.cdist(xn, lambda x, y: np.abs(x - y).max()).

Parameters
• x (Tensor) – A tensor with shape $$B \times P \times M$$.

• y (Tensor) – A tensor with shape $$B \times R \times M$$.

• p (float, optional) – The value for the p-norm distance to calculate between each vector pair. Default: $$2.0$$.

• compute_mode (str, optional) –

The mode for compute distance.

• use_mm_for_euclid_dist_if_necessary , for p = 2.0 and (P > 25 or R > 25), it will use matrix multiplication to calculate euclid distance if possible.

• use_mm_for_euclid_dist , for p = 2.0, it will use matrix multiplication to calculate euclid distance.

• donot_use_mm_for_euclid_dist , it will not use matrix multiplication to calculate euclid distance.

Default: use_mm_for_euclid_dist_if_necessary.

• name (str, optional) – For details, please refer to Name. Generally, no setting is required. Default: None.

Returns

Tensor, the dtype is same as input tensor.

If x has shape $$B \times P \times M$$ and y has shape $$B \times R \times M$$ then the output will have shape $$B \times P \times R$$.

Examples

import paddle