@@ -182,7 +182,7 @@ def euclidean_distances(X, Y, squared=False):
182182 return c
183183
184184
185- def dist (x1 , x2 = None , metric = 'sqeuclidean' , p = 2 ):
185+ def dist (x1 , x2 = None , metric = 'sqeuclidean' , p = 2 , w = None ):
186186 r"""Compute distance between samples in :math:`\mathbf{x_1}` and :math:`\mathbf{x_2}`
187187
188188 .. note:: This function is backend-compatible and will work on arrays
@@ -202,6 +202,10 @@ def dist(x1, x2=None, metric='sqeuclidean', p=2):
202202 'euclidean', 'hamming', 'jaccard', 'kulsinski', 'mahalanobis',
203203 'matching', 'minkowski', 'rogerstanimoto', 'russellrao', 'seuclidean',
204204 'sokalmichener', 'sokalsneath', 'sqeuclidean', 'wminkowski', 'yule'.
205+ p : float, optional
206+ p-norm for the Minkowski and the Weighted Minkowski metrics. Default value is 2.
207+ w : array-like, rank 1
208+ Weights for the weighted metrics.
205209
206210
207211 Returns
@@ -221,7 +225,9 @@ def dist(x1, x2=None, metric='sqeuclidean', p=2):
221225 if not get_backend (x1 , x2 ).__name__ == 'numpy' :
222226 raise NotImplementedError ()
223227 else :
224- return cdist (x1 , x2 , metric = metric , p = p )
228+ if metric .endswith ("minkowski" ):
229+ return cdist (x1 , x2 , metric = metric , p = p , w = w )
230+ return cdist (x1 , x2 , metric = metric , w = w )
225231
226232
227233def dist0 (n , method = 'lin_square' ):
0 commit comments