python-igraph API reference

List of all classes, functions and methods in python-igraph

class documentation

class Clustering:

Known subclasses: igraph.clustering.VertexClustering

View In Hierarchy

Class representing a clustering of an arbitrary ordered set.

This is now used as a base for VertexClustering, but it might be useful for other purposes as well.

Members of an individual cluster can be accessed by the [] operator:

>>> cl = Clustering([0,0,0,0,1,1,1,2,2,2,2])
>>> cl[0]
[0, 1, 2, 3]

The membership vector can be accessed by the membership property:

>>> cl.membership
[0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2]

The number of clusters can be retrieved by the len function:

>>> len(cl)
3

You can iterate over the clustering object as if it were a regular list of clusters:

>>> for cluster in cl:
...     print(" ".join(str(idx) for idx in cluster))
...
0 1 2 3
4 5 6
7 8 9 10

If you need all the clusters at once as lists, you can simply convert the clustering object to a list:

>>> cluster_list = list(cl)
>>> print(cluster_list)
[[0, 1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]
Method __init__ Constructor.
Method __getitem__ Returns the members of the specified cluster.
Method __iter__ Iterates over the clusters in this clustering.
Method __len__ Returns the number of clusters.
Method __str__ Undocumented
Method as_cover Returns a Cover that contains the same clusters as this clustering.
Method compare_to Compares this clustering to another one using some similarity or distance metric.
Property membership Returns the membership vector.
Property n Returns the number of elements covered by this clustering.
Method size Returns the size of a given cluster.
Method sizes Returns the size of given clusters.
Method size_histogram Returns the histogram of cluster sizes.
Method summary Returns the summary of the clustering.
Instance Variable _membership Undocumented
Instance Variable _len Undocumented
Method _formatted_cluster_iterator Iterates over the clusters and formats them into a string to be presented in the summary.
def __init__(self, membership, params=None):

Constructor.

Parametersmembershipthe membership list -- that is, the cluster index in which each element of the set belongs to.
paramsadditional parameters to be stored in this object's dictionary.
_membership =

Undocumented

_len =

Undocumented

(type: int)
def __getitem__(self, idx):

Returns the members of the specified cluster.

Parametersidxthe index of the cluster
Returnsthe members of the specified cluster as a list
RaisesIndexErrorif the index is out of bounds
def __iter__(self):

Iterates over the clusters in this clustering.

This method will return a generator that generates the clusters one by one.

def __len__(self):

Returns the number of clusters.

Returnsthe number of clusters
def __str__(self):

Undocumented

def as_cover(self):

Returns a Cover that contains the same clusters as this clustering.

def compare_to(self, other, *args, **kwds):

Compares this clustering to another one using some similarity or distance metric.

This is a convenience method that simply calls compare_communities with the two clusterings as arguments. Any extra positional or keyword argument is also forwarded to compare_communities.

@property
membership =

Returns the membership vector.

@property
n =

Returns the number of elements covered by this clustering.

def size(self, idx):

Returns the size of a given cluster.

Parametersidxthe cluster in which we are interested.
def sizes(self, *args):

Returns the size of given clusters.

The indices are given as positional arguments. If there are no positional arguments, the function will return the sizes of all clusters.

def size_histogram(self, bin_width=1):

Returns the histogram of cluster sizes.

Parametersbin_widththe bin width of the histogram
Returnsa Histogram object
def summary(self, verbosity=0, width=None):

Returns the summary of the clustering.

The summary includes the number of items and clusters, and also the list of members for each of the clusters if the verbosity is nonzero.

Parametersverbositydetermines whether the cluster members should be printed. Zero verbosity prints the number of items and clusters only.
widthUndocumented
Returnsthe summary of the clustering as a string.
def _formatted_cluster_iterator(self):

Iterates over the clusters and formats them into a string to be presented in the summary.

API Documentation for igraph, generated by pydoctor 21.2.2.