MCPcopy
hub / github.com/networkx/networkx / remove_node

Method remove_node

networkx/classes/digraph.py:579–620  ·  view source on GitHub ↗

Remove node n. Removes the node n and all adjacent edges. Attempting to remove a nonexistent node will raise an exception. Parameters ---------- n : node A node in the graph Raises ------ NetworkXError If n is n

(self, n)

Source from the content-addressed store, hash-verified

577 nx._clear_cache(self)
578
579 def remove_node(self, n):
580 """Remove node n.
581
582 Removes the node n and all adjacent edges.
583 Attempting to remove a nonexistent node will raise an exception.
584
585 Parameters
586 ----------
587 n : node
588 A node in the graph
589
590 Raises
591 ------
592 NetworkXError
593 If n is not in the graph.
594
595 See Also
596 --------
597 remove_nodes_from
598
599 Examples
600 --------
601 >>> G = nx.path_graph(3) # or DiGraph, MultiGraph, MultiDiGraph, etc
602 >>> list(G.edges)
603 [(0, 1), (1, 2)]
604 >>> G.remove_node(1)
605 >>> list(G.edges)
606 []
607
608 """
609 try:
610 nbrs = self._succ[n]
611 del self._node[n]
612 except KeyError as err: # NetworkXError if n not in self
613 raise NetworkXError(f"The node {n} is not in the digraph.") from err
614 for u in nbrs:
615 del self._pred[u][n] # remove all edges n-u in digraph
616 del self._succ[n] # remove node from succ
617 for u in self._pred[n]:
618 del self._succ[u][n] # remove all edges n-u in digraph
619 del self._pred[n] # remove node from pred
620 nx._clear_cache(self)
621
622 def remove_nodes_from(self, nodes):
623 """Remove multiple nodes.

Callers 5

test_const_fail_casesMethod · 0.95
unfeasible_errorMethod · 0.95
runtime_error2Method · 0.95

Calls 1

NetworkXErrorClass · 0.90

Tested by 5

test_const_fail_casesMethod · 0.76
unfeasible_errorMethod · 0.76
runtime_error2Method · 0.76