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

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
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.
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.
python Create a new file name condition_quiz.py. Add a comment with your name and the date....
python Create a new file name condition_quiz.py. Add a comment with your name and the date. Prompt the user to enter the cost. Convert the input to a float. Prompt the user for a status. Convert the status to an integer Compute the special_fee based on the status. If the status is 0, the special_fee will be 0.03 of the cost. Else if the status is 1, the special_fee will be 0.04 of the cost. Else if the status is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT