NetworkX

Previous topic

Clustering

Next topic

networkx.transitivity

Quick search

networkx.triangles

triangles(G, nbunch=None, with_labels=False)

Compute the number of triangles.

Finds the number of triangles that include a node as one of the vertices.

Parameters:

G : graph

A networkx graph

nbunch : container of nodes, optional

Compute triangles for nodes in nbunch. The default is all nodes in G.

with_labels: bool, optional :

If True return a dictionary keyed by node label.

Returns:

out : list or dictionary

Number of trianges

Notes

When computing triangles for the entire graph each triangle is counted three times, once at each node.