當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python SciPy spatial.distance_matrix用法及代碼示例

本文簡要介紹 python 語言中 scipy.spatial.distance_matrix 的用法。

用法:

scipy.spatial.distance_matrix(x, y, p=2, threshold=1000000)#

計算距離矩陣。

返回所有成對距離的矩陣。

參數

x (M, K) 數組

K 維 M 向量矩陣。

y (N, K) 數組

K 維的 N 個向量的矩陣。

p 浮點數,1 <= p <= 無窮大

使用哪個 Minkowski p-norm。

threshold 正int

如果M * N * K>臨界點,算法使用Python循環而不是大型臨時數組。

返回

result (M, N) ndarray

包含從 x 中的每個向量到 y 中的每個向量的距離的矩陣。

例子

>>> from scipy.spatial import distance_matrix
>>> distance_matrix([[0,0],[0,1]], [[1,0],[1,1]])
array([[ 1.        ,  1.41421356],
       [ 1.41421356,  1.        ]])

相關用法


注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.spatial.distance_matrix。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。