Question: Complete the calculate _ inter _ community _ density function to calculate the intercommunity connection density matrix ( see matrix P in L 1 2

Complete the calculate_inter_community_density function to calculate the
intercommunity connection density matrix (see matrix P in L12: Generating Networks
with Community Structure for the definition).
Additionally, complete the plot_p_matrix function to plot the inter-community detection
density matrix as a heatmap. Make sure to annotate the values within each cell and
provide a legend.
def calculate_inter_community_density(G: nx.Graph, partition: list)-> Tuple[np.ndarray, List[int]]:
"""
Inputs:
G: NetworkX graph object
partition : list
Returns:
Tuple of np array and List[int], intercommunity connection density matrix
"""
return p, sizes
def plot_p_matrix(p: np.ndarray, save: bool=False):
"""
Inputs:
p: np array, intercommunity connection density matrix
save: boolean
Returns:
None
"""
if save:
plt.savefig('1_3.png')
plt.show()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!