Intermediate Network Analysis in Python
Eric Ma
Data Carpentry instructor and author of nxviz package
cust_nodes = [n for n in G.nodes() if G.nodes[n] ['bipartite'] == 'customers'] prod_nodes = [n for n in G.nodes() if G.nodes[n] ['bipartite'] == 'products']
mat = nx.bipartite.biadjacency_matrix(G, row_order=cust_nodes, column_order=prod_nodes)
mat
<3x2 sparse matrix of type '<class 'numpy.int64'>'
with 3 stored elements in Compressed Sparse Row format>
mat @ mat.T
<5x5 sparse matrix of type '<class 'numpy.int64'>'
with 23 stored elements in Compressed Sparse Row format>
mat.T @ mat
<10x10 sparse matrix of type '<class 'numpy.int64'>'
with 50 stored elements in Compressed Sparse Column format>
Intermediate Network Analysis in Python