Answers for "networkx remove nodes"

1

networkx remove nodes with degree

import networkx

G1 = networkx.Graph()
G1.add_edges_from([('a','b'),('b','c'),('c','e'),('c','d'),('c','f'),('c','g')])
to_be_removed = [x for  x in G1.nodes() if G1.degree(x) <= 1]

for x in to_be_removed:
    G1.remove_node(x)

print(G1.edges())
Posted by: Guest on February-24-2021
0

newtorkx remove node

import networkx as nx

graph = nx.Graph()
graph.add_node('a')
graph.nodes
# NodeView(('a',))

graph.remove_node('a')
# NodeView(())
Posted by: Guest on August-03-2020

Python Answers by Framework

Browse Popular Code Answers by Language