networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
attribute_mixing_matrix(G, attribute, nodes=None, mapping=None, normalized=True)

Notes

If each node has a unique attribute value, the unnormalized mixing matrix will be equal to the adjacency matrix. To get a denser mixing matrix, the rounding can be performed to form groups of nodes with equal values. For example, the exact height of persons in cm (180.79155222, 163.9080892, 163.30095355, 167.99016217, 168.21590163, ...) can be rounded to (180, 163, 163, 168, 168, ...).

Definitions of attribute mixing matrix vary on whether the matrix should include rows for attribute values that don't arise. Here we do not include such empty-rows. But you can force them to appear by inputting a :None:None:`mapping` that includes those values.

Parameters

G : graph

NetworkX graph object.

attribute : string

Node attribute key.

nodes: list or iterable (optional) :

Use only nodes in container to build the matrix. The default is all nodes.

mapping : dictionary, optional

Mapping from node attribute to integer index in matrix. If not specified, an arbitrary ordering will be used.

normalized : bool (default=True)

Return counts if False or probabilities if True.

Returns

m: numpy array

Counts or joint probability of occurrence of attribute pairs.

Returns mixing matrix for attribute.

Examples

>>> G = nx.path_graph(3)
... gender = {0: 'male', 1: 'female', 2: 'female'}
... nx.set_node_attributes(G, gender, 'gender')
... mapping = {'male': 0, 'female': 1}
... mix_mat = nx.attribute_mixing_matrix(G, 'gender', mapping=mapping)
... # mixing from male nodes to female nodes
... mix_mat[mapping['male'], mapping['female']] 0.25
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.assortativity.mixing.attribute_mixing_matrix

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/assortativity/mixing.py#55
type: <class 'function'>
Commit: