Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

second contribution #38

Merged
merged 6 commits into from
Apr 4, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions 2022-round-1/deepthi1107/nx_tutorial_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python
# coding: utf-8

# In[1]:


#importing the required libraries
import networkx as nx


# In[2]:


#Creating DiGraph
graph1=nx.DiGraph()


# In[3]:


#adding node 11,"N1",1,2,3
graph1.add_node(11)
graph1.add_node("N1")
L=[1,2,3]
graph1.add_nodes_from(L)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @deepthi1107!

Could you also add a tuple object as a node. Currently there are only int and str type objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, @MridulS.



# In[4]:


#view of all the nodes inserted to the DiGraph
graph1.nodes()


# In[5]:


#adding edges 11->"N1","N1"->1,1->2,2->3,3->11
graph1.add_edge(11,"N1")
graph1.add_edge("N1",1)
graph1.add_edge(1,2)
graph1.add_edge(2,3)
graph1.add_edge(3,11)


# In[6]:


#view of edges, connecting the nodes
graph1.edges()


# In[7]:


#visualization of DiGraph created
nx.draw(graph1,with_labels=1)


# In[8]:


#finding the shoretes path between the nodes and printing the shortest path
s_path = nx.shortest_path(graph1)
print(s_path)