Question: CHW 5 . 2 . Graphs: Meme spread in social networks Graphs can be used in mathematics and other fields to represent objects and the
CHW Graphs: Meme spread in social networks
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 edgenode incidence matrix of this graph. It is stored as a Dnumpy array friends.
Find the number of friend groups of this network. Store this value as numfriendgroups. This should be the number of connected components in this directed graph.
Assuming that a meme originates at person assume zeroindexing 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 nummemespread.
We also give you a function nullspace. Given a matrix as a numpy array of shape this function will return an numpy array of shape consisting of a basis of the nullspace of the original matrix.
The setup code gives the following variables:
The setup code gives the following variables:
tableNameType,Descriptionfriendsnumpy array,edgenode incidence matrixnullspacefunction,returns basis of nullspace of a matrix
Your code snippet should define the following variables:
tableNameType,Descriptionnumfriendgroups,integer,Number of overall friend groupsnummemespread,integer,Number of people that will receive the meme
usercode.py
limport numpy as
import numpy.linalg as a
numfriendgroups dots
nummemespread dots
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
