In [0]:
%pylab inline
Assign your name to a variable called "my_name".
Print your name using "print" function.
https://docs.python.org/3/tutorial/introduction.html#strings.
In [0]:
Define a list called "nodes" of 10 nodes (0, 1, ..., 9) using "range" function.
Convert the range into a list using "list" function.
Print the list of nodes using "print" function.
https://docs.python.org/3/tutorial/introduction.html#lists
https://docs.python.org/3/tutorial/controlflow.html#the-range-function
In [0]:
In [0]:
Use "zip" function to create a sequence of tuple and called it "edges".
Each tuple defines an edge between two nodes from the list nodes
and the list studid (nodes[i], stud[i]).
Then, use "list" function to convert "edges" sequence into a list.
Print the list of edges using "print" function.
Example:
If nodes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] and studid = [2, 0, 1, 5, 2, 3, 4, 0, 3, 1]
then, edges = [(0, 2), (1, 0), (2, 1), (3, 5), (4, 2), (5, 3), (6, 4), (7, 0), (8, 3), (9, 1)]
https://docs.python.org/3/tutorial/datastructures.html#nested-list-comprehensions
In [0]:
Import networkx module as nx.
Then, create an empty graph G with no nodes and no edges.
https://networkx.github.io/documentation/stable/tutorial.html#creating-a-graph
In [0]:
Add "edges" to G using "add_edges_from" function.
https://networkx.github.io/documentation/stable/tutorial.html#edges
In [0]:
Print all nodes using "list" and print" function.
https://networkx.github.io/documentation/stable/tutorial.html#edges
In [0]:
Print all edges using "list" and print" function.
https://networkx.github.io/documentation/stable/tutorial.html#edges
In [0]:
Print the number of nodes using
"number_of_nodes" functon, and
"print" function.
https://networkx.github.io/documentation/stable/tutorial.html#edges
In [0]:
In [0]:
Print the list of nodes adjacent to node 2 (neighbour of node 2)
using "neighbors" function
and "print" function.
https://networkx.github.io/documentation/stable/tutorial.html#edges
In [0]:
Print all the nodes and a list of their respective neighbours side by side using
"for loop",
"nodes" function,
"neighbors" function, and
"print" function.
Example:
0 [1, 2, 7]
1 [0, 9, 2]
2 [0, 1, 4]
3 [8, 5]
4 [2, 6]
5 [3]
6 [4]
7 [0]
8 [3]
9 [1]
https://docs.python.org/3/tutorial/controlflow.html#for-statements
https://networkx.github.io/documentation/stable/tutorial.html#edges
In [0]:
Print the degree for node 2 using the "degree" function , and
"print" function.
Please ignore parameter "weight".
https://networkx.github.io/documentation/stable/tutorial.html#edges
In [0]:
Print all the nodes and their respective degree side by side using
"for loop",
"nodes" function,
"degree" function, and
"print" function.
Example:
0 3
1 3
2 3
3 2
4 2
5 1
6 1
7 1
8 1
9 1
https://docs.python.org/3/tutorial/controlflow.html#for-statements
https://networkx.github.io/documentation/stable/tutorial.html#edges
In [0]:
"G.degree()" is of type dict.
"G.degree().keys()" will return all the nodes.
"G.degree().values()" will return all the degrees.
Create a degree sequence in descending order using
"G.degree().values()" function and "list" function
and assign it to variable called "degree_sequence"
Print "degree_sequence" using "print" function.
Note:
Example:
[3, 3, 3, 2, 2, 1, 1, 1, 1, 1]
https://docs.python.org/3/tutorial/introduction.html#lists
https://docs.python.org/3/tutorial/datastructures.html#dictionaries
In [0]:
In [0]:
In [0]:
In [0]:
Calculate the value of 2 times the total number of edges using
"number_of_edges" function, and
assign it to a variable called "edges_times2".
Print "edges_times2" using "print" function.
Example:
edges_times2 = 2 x number_of_edges = 18
https://networkx.github.io/documentation/stable/tutorial.html#edges
In [0]:
In [0]:
In [0]: