@@ -182,7 +182,7 @@ def euclidean_distances(X, Y, squared=False):
182
182
return c
183
183
184
184
185
- def dist (x1 , x2 = None , metric = 'sqeuclidean' , p = 2 ):
185
+ def dist (x1 , x2 = None , metric = 'sqeuclidean' , p = 2 , w = None ):
186
186
r"""Compute distance between samples in :math:`\mathbf{x_1}` and :math:`\mathbf{x_2}`
187
187
188
188
.. note:: This function is backend-compatible and will work on arrays
@@ -202,6 +202,10 @@ def dist(x1, x2=None, metric='sqeuclidean', p=2):
202
202
'euclidean', 'hamming', 'jaccard', 'kulsinski', 'mahalanobis',
203
203
'matching', 'minkowski', 'rogerstanimoto', 'russellrao', 'seuclidean',
204
204
'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.
205
209
206
210
207
211
Returns
@@ -221,7 +225,9 @@ def dist(x1, x2=None, metric='sqeuclidean', p=2):
221
225
if not get_backend (x1 , x2 ).__name__ == 'numpy' :
222
226
raise NotImplementedError ()
223
227
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 )
225
231
226
232
227
233
def dist0 (n , method = 'lin_square' ):
0 commit comments