Affiliation networks are represented in NetworkX using the same classes as other networks: Graph and DiGraph. The only difference is that you need to keep track of which nodes are of which type. In NetworkX, this is done by using a container (list, set, and so on) to store all node IDs for one node type. For convenience, the node type can also be stored as a node attribute. A network can be tested for an affiliation network structure using the sets() function. Usually, this function can also find the nodes of each type (the exception being when the network has groups of nodes that are not connected to the rest of the network). The following example loads our dear old friend from Chapter 2, Working with Networks ...
Affiliation networks in NetworkX
Get Network Science with Python and NetworkX Quick Start Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.