Question

In: Computer Science

PYTHON First, create an ER random graph with N=100 and p=0.1 and name it G. Then...

PYTHON

First, create an ER random graph with N=100 and p=0.1 and name it G. Then use the histogram() function to draw a histogram of the node degrees for the graph G. Don't worry about filling in "missing" values.

Also print the mean, median, and mode of the node degree distribution. Execute this a few times.

Note: while histogram(G.degree()) does draw a plot, that plot is not a histogram. Doing so will result in zero credit for this exercise.

Solutions

Expert Solution

import networkx as nx  

import matplotlib.pyplot as plt

import numpy as np

import statistics

G= nx.erdos_renyi_graph(100,0.1)

nodes = nx.nodes(G)

degrees = []

for v in nodes:

    degrees.append(nx.degree(G, v))

plt.hist(degrees,color = 'green')

plt.show()

print("Mean: ",np.mean(degrees))

print("Median: ",np.median(degrees))

print("Mode: ",statistics.mode(degrees))


Related Solutions

X1 is a binomial random variable with n = 100 and p = 0.8, while X2...
X1 is a binomial random variable with n = 100 and p = 0.8, while X2 is a binomial random variable with n = 100 and p = 0.2. The variables are independent. The profit measure is given by P = X1 / X2. Run N = 10 simulations of X1 and X2 to simulate the distribution of P, and then find both the variance and the semi-variance.
Short Python 3 questions a. Create a dictionary that maps the first n counting numbers to...
Short Python 3 questions a. Create a dictionary that maps the first n counting numbers to their squares. Assign the dictionary to the variable squares b. Given the list value_list, assign the number of nonduplicate values to the variable distinct_values
Given a binomial random variable with n​ = 100 and p​ = .5​, estimate the​ Pr[X...
Given a binomial random variable with n​ = 100 and p​ = .5​, estimate the​ Pr[X ≥ 40​]
Consider 100 g of aluminum (p = 2700 kg/m^3) and 100 g of lead (p =...
Consider 100 g of aluminum (p = 2700 kg/m^3) and 100 g of lead (p = 11,300 kg/m^3). a. Which as a greater volume? Show why this is true mathematically. b. Which contains a larger number of moles? Show why this is true mathematically. c. Which contains more atoms? Show why this is true mathematically. A 685-liter oxygen tank contains oxygen gas at 20℃ . When the tank is full, the pressure gauge reads 3000 psi. a. How many oxygen...
Give an example of a graph G with p(G) = 7 and c(G) = 3.
Give an example of a graph G with p(G) = 7 and c(G) = 3.
Create an ER diagram for the requirements below. - Parts have a unique number, name, and...
Create an ER diagram for the requirements below. - Parts have a unique number, name, and production year. - Car company has a unique number, name and country information -Automakers make multiple cars. It has a serial number and a name. but, There can be no more than two companies making one car. -Parts are used in many cars. When a part is used in a car, Save the part usage date and quantity information.
Assume that x is a binominal random variable with n=100 and p=0.40. Use a normal approximation...
Assume that x is a binominal random variable with n=100 and p=0.40. Use a normal approximation to find the following: a) P(x≥38) b) P(x=45) c) P(x>45) d) P(x<45)
A maximal plane graph is a plane graph G = (V, E) with n ≥ 3...
A maximal plane graph is a plane graph G = (V, E) with n ≥ 3 vertices such that if we join any two non-adjacent vertices in G, we obtain a non-plane graph. a) Draw a maximal plane graphs on six vertices. b) Show that a maximal plane graph on n points has 3n − 6 edges and 2n − 4 faces. c) A triangulation of an n-gon is a plane graph whose infinite face boundary is a convex n-gon...
Prove that if G is a simple graph with |V (G)| = n even, where δ(G)...
Prove that if G is a simple graph with |V (G)| = n even, where δ(G) ≥ n 2 + 1, then G has a 3-regular spanning subgraph.
Given a connected graph G with n vertices. We say an edge of G is a...
Given a connected graph G with n vertices. We say an edge of G is a bridge if the graph becomes a disconnected graph after removing the edge. Give an O(m + n) time algorithm that finds all the bridges. (Partial credits will be given for a polynomial time algorithm.) (Hint: Use DFS)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT