# pairwise_distances

### cuml.metrics.pairwise_distances(X, Y=None, metric='euclidean', \*\*kwds)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/metrics/pairwise_distances.pyx#L258)

Compute the distance matrix from a feature array X and optional Y.

This function takes either one or two feature arrays, and returns
a distance matrix.

* **Parameters:**
  **X**
  : A feature array.

  **Y**
  : A second feature array. If None, Y=X will be used.

  **metric**
  : The metric to use when calculating distance between instances in a
    feature array. Valid options are:
    - Supports both dense and sparse data: [‘canberra’, ‘chebyshev’,
      ‘cityblock’, ‘cosine’, ‘euclidean’, ‘hellinger’, ‘l1’, ‘l2’,
      ‘manhattan’, ‘minkowski’, ‘sqeuclidean’].
    - Supports dense only: [‘correlation’, ‘hamming’, ‘jensenshannon’,
      ‘kldivergence’, ‘nan_euclidean’, ‘russellrao’].
    - Supports sparse only: [‘dice’, ‘inner_product’, ‘jaccard’].

  **\*\*kwds**
  : Additional metric-specific parameters:
    - `minkowski`:
      - `p` : float, default=2.0
        The p-norm to apply for Minkowski distance. `p=1` gives
        Manhattan distance, `p=2` gives Euclidean distance.
    - `nan_euclidean`:
      - `squared` : bool, default=False
        Return squared Euclidean distances.
      - `missing_values` : np.nan or int, default=np.nan
        Representation of missing values in the input data.
      - `copy` : bool, default=True
        Whether to make a copy of X and Y when necessary. Setting
        to `False` can reduce memory usage, but may result in
        mutation of X and Y.
    <br/>
    All other metrics do not accept additional keyword parameters.
    Passing unknown parameters raises a `TypeError`.
* **Returns:**
  **D**
  : A distance matrix D such that D_{i, j} is the distance between the ith
    and jth vectors of the given matrix X, if Y is None. If Y is not None,
    then D_{i, j} is the distance between the ith array from X and the jth
    array from Y.

### Examples

```pycon
>>> import cupy as cp
>>> from cuml.metrics import pairwise_distances
```

```pycon
>>> X = cp.array([[0., 0., 0.], [1., 1., 1.]])
>>> Y = cp.array([[1., 0., 0.], [1., 1., 0.]])
```

```pycon
>>> pairwise_distances(X, metric="sqeuclidean")
array([[0., 3.],
       [3., 0.]])
```

```pycon
>>> pairwise_distances(X, Y, metric="sqeuclidean")
array([[1., 2.],
       [2., 1.]])
```

<!-- !! processed by numpydoc !! -->
