Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i wrote in the get_incidence_matrix, not sure if right in python please Graphs can be used in mathematics and other fields to represent objects and

image text in transcribed
image text in transcribed
i wrote in the get_incidence_matrix, not sure if right
in python please
Graphs can be used in mathematics and other fields to represent objects and the connections between them. Here, we will use a directed graph to represent people in a social network and their friend connections with one another. In this directed graph nodes correspond to people. An edge between two nodes indicates frienship between the correspding people. The direction of the edge is chosen at random and carries no further meaning. A friend group is a connected component of this graph. We will use this to model the spread of a meme throughout this theoretical social network. We give you the edge-node incidence matrix of this graph. It is stored as a 2D-numpy array friends. 1) Find the number of friend groups of this network, Store this value as num friend groups. This should be the number of connected components in this directed graph. 2) Assuming that a meme originates at person 38 (assume zero-indexing), find the number of people that will see the meme (including the original person). Assume each person will send the meme to all of their friends. Save this as num_mene_spread. We also give you a function nullspace. Given a matrix as a 2d-numpy array of shape (m, n), this function will return an 2d-numpy array of shape (n. d) consisting of a basis of the nullspace of the original matrix The setup code gives the following variables: Name Type friends numpy array function Description edge-node incidence matrix returns basis of nullspace of a matrix nullspace Your code snippet should define the following variables: Name Type integer num friend_eroups Description Number of overall friend groups Number of people that will receive the meme num_meme_spread integer user_code.py 8. 1 import numpy as np 2 Import numpy. linals as la 3 4. def get_Incidence_matrix(friends): 5 n. len(friends) number of nodes 6 np.count_nonzero(friends) number of edges 7 M - np.zeros((m,n)), astype(int) 1. for 1 in range(n): 10- for in range(n): 11 - if ((friends[1.31 - 0) & (11-1)); 12 M[1,1] - 1 13 [1,1] - 1 1 - 1 15 return M 16 17 n = get_Incidence_matrix(friends) 18 n_groups - nullspace(n) num_friend groups - n groups. shape [1] 19 Cinnad Graphs can be used in mathematics and other fields to represent objects and the connections between them. Here, we will use a directed graph to represent people in a social network and their friend connections with one another. In this directed graph nodes correspond to people. An edge between two nodes indicates frienship between the correspding people. The direction of the edge is chosen at random and carries no further meaning. A friend group is a connected component of this graph. We will use this to model the spread of a meme throughout this theoretical social network. We give you the edge-node incidence matrix of this graph. It is stored as a 2D-numpy array friends. 1) Find the number of friend groups of this network, Store this value as num friend groups. This should be the number of connected components in this directed graph. 2) Assuming that a meme originates at person 38 (assume zero-indexing), find the number of people that will see the meme (including the original person). Assume each person will send the meme to all of their friends. Save this as num_mene_spread. We also give you a function nullspace. Given a matrix as a 2d-numpy array of shape (m, n), this function will return an 2d-numpy array of shape (n. d) consisting of a basis of the nullspace of the original matrix The setup code gives the following variables: Name Type friends numpy array function Description edge-node incidence matrix returns basis of nullspace of a matrix nullspace Your code snippet should define the following variables: Name Type integer num friend_eroups Description Number of overall friend groups Number of people that will receive the meme num_meme_spread integer user_code.py 8. 1 import numpy as np 2 Import numpy. linals as la 3 4. def get_Incidence_matrix(friends): 5 n. len(friends) number of nodes 6 np.count_nonzero(friends) number of edges 7 M - np.zeros((m,n)), astype(int) 1. for 1 in range(n): 10- for in range(n): 11 - if ((friends[1.31 - 0) & (11-1)); 12 M[1,1] - 1 13 [1,1] - 1 1 - 1 15 return M 16 17 n = get_Incidence_matrix(friends) 18 n_groups - nullspace(n) num_friend groups - n groups. shape [1] 19 Cinnad

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

1. What are your creative strengths?

Answered: 1 week ago

Question

13. You always should try to make a good first impression.

Answered: 1 week ago