SciPy - centeroid() 方法
SciPy centeroid() 方法是一个一维数组,其中的数据值是借助平均权重计算的,这些权重本身代表一个值。
语法
以下是 SciPy centeroid() 方法的语法 −
centeroid(y)
参数
此方法仅接受单个参数 −
- y:它是 pdist() 形式的数据元素数组。
返回值
此方法以以下形式返回结果链接矩阵。
示例
以下是说明 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.html