成對曼哈頓距離#

sklearn.metrics.pairwise.paired_manhattan_distances(X, Y)[來源]#

計算 X 和 Y 之間的成對 L1 距離。

距離計算在 (X[0], Y[0]), (X[1], Y[1]), …, (X[n_samples], Y[n_samples]) 之間。

使用者指南中閱讀更多。

參數:
X形狀為 (n_samples, n_features) 的 {類陣列, 稀疏矩陣}

一個類似陣列的結構,其中每一列是一個樣本,每一欄是一個特徵。

Y{類似陣列, 稀疏矩陣},形狀為 (n_samples, n_features)

一個類似陣列的結構,其中每一列是一個樣本,每一欄是一個特徵。

回傳值:
distances形狀為 (n_samples,) 的 ndarray

X 的列向量與 Y 的列向量之間的 L1 配對距離。

範例

>>> from sklearn.metrics.pairwise import paired_manhattan_distances
>>> import numpy as np
>>> X = np.array([[1, 1, 0], [0, 1, 0], [0, 0, 1]])
>>> Y = np.array([[0, 1, 0], [0, 0, 1], [0, 0, 0]])
>>> paired_manhattan_distances(X, Y)
array([1., 2., 1.])