Compute adjacency matrix
Now, you'll get some practice using matrices and sparse matrix multiplication to compute projections! In this exercise, you'll use the matrix multiplication operator @ that was introduced in Python 3.5.
You'll continue working with the American Revolution graph. The two partitions of interest here are 'people' and 'clubs'.
Questo esercizio fa parte del corso
Intermediate Network Analysis in Python
Istruzioni dell'esercizio
- Get the list of people and list of clubs from the graph
Gusing theget_nodes_from_partition()function that you defined in the previous chapter. This function accepts two parameters: A graph, and a partition. - Compute the biadjacency matrix using
nx.bipartite.biadjacency_matrix(), setting therow_orderparameter topeople_nodesand thecolumn_orderparameter toclubs_nodes. Remember to also pass in the graphG. - Compute the user-user projection by multiplying (with the
@operator) the biadjacency matrixbi_matrixby its transposition,bi_matrix.T.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Get the list of people and list of clubs from the graph: people_nodes, clubs_nodes
people_nodes = ____
clubs_nodes = ____
# Compute the biadjacency matrix: bi_matrix
bi_matrix = ____(____, row_order=____, column_order=____)
# Compute the user-user projection: user_matrix
user_matrix = ____
print(user_matrix)