1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Network Analysis in Python

Connected

Exercise

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'.

Instructions

100 XP
  • Get the list of people and list of clubs from the graph G using the get_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 the row_order parameter to people_nodes and the column_order parameter to clubs_nodes. Remember to also pass in the graph G.
  • Compute the user-user projection by multiplying (with the @ operator) the biadjacency matrix bi_matrix by its transposition, bi_matrix.T.