SciPy - centeroid() 方法



SciPy centeroid() 方法是一個一維陣列,其中資料值在平均權重的幫助下計算得出,而這些權重本身表示一個值。

語法

以下是 SciPy centeroid() 方法的語法 −

centeroid(y)

引數

此方法僅接受一個引數 −

  • y: 它是採用 pdist() 形式的資料元素陣列。

返回值

此方法返回的 Ergebnis 是連鎖矩陣。

示例

以下是演示 SciPy centeroid() 方法用法的基本示例。

from scipy.cluster.hierarchy import centroid, fcluster
from scipy.spatial.distance import pdist
X = [[0, 0], [0, 1], [1, 0],
     [0, 4], [0, 3], [1, 4],
     [4, 0], [3, 0], [4, 1],
     [4, 4], [3, 4], [4, 3]]
y = pdist(X)
res = centroid(y)
print(res)

輸出

以上程式碼產生以下結果 −

[[ 0.          1.          1.          2.        ]
 [ 3.          4.          1.          2.        ]
 [ 9.         10.          1.          2.        ]
 [ 6.          7.          1.          2.        ]
 [ 2.         12.          1.11803399  3.        ]
 [ 5.         13.          1.11803399  3.        ]
 [ 8.         15.          1.11803399  3.        ]
 [11.         14.          1.11803399  3.        ]
 [18.         19.          3.33333333  6.        ]
 [16.         17.          3.33333333  6.        ]
 [20.         21.          3.33333333 12.        ]]
scipy_reference.htm
廣告
© . All rights reserved.