Selected Reading

SciPy - centeroid() Method



The SciPy centeroid() method is an one-dimensional array in which data values are calculated with the help of average weight and these weights itself represent a value.

Syntax

Following is the syntax of the SciPy centeroid() method −

centeroid(y)

Parameters

This method accepts only a single parameter −

  • y: It is an array of data element in the form of pdist().

Return value

This methods returns the result in form of linkage matrix.

Example

Following is the basic example that illustrate the usage of SciPy centeroid() method.

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)

Output

The above code produces the following result −

[[ 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
Advertisements