MulaiMulai sekarang secara gratis

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

Latihan ini adalah bagian dari kursus

Intermediate Network Analysis in Python

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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)
Edit dan Jalankan Kode