Skip to content

Commit 106483a

Browse files
authored
Merge pull request #118 from JanMarcoRuizdeVargas/patch-1
Update GeneralGraph.py
2 parents 8fa5ee3 + 6da7d18 commit 106483a

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

causallearn/graph/GeneralGraph.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -865,20 +865,21 @@ def remove_nodes(self, nodes: List[Node]):
865865
# nodes of this graph together with the edges between them.
866866
def subgraph(self, nodes: List[Node]):
867867
subgraph = GeneralGraph(nodes)
868-
868+
869869
graph = self.graph
870-
870+
871+
nodes_to_delete = []
872+
871873
for i in range(self.num_vars):
872874
if not (self.nodes[i] in nodes):
873-
graph = np.delete(graph, i, axis=0)
874-
875-
for i in range(self.num_vars):
876-
if not (self.nodes[i] in nodes):
877-
graph = np.delete(graph, i, axis=1)
878-
875+
nodes_to_delete.append(i)
876+
877+
graph = np.delete(graph, nodes_to_delete, axis = 0)
878+
graph = np.delete(graph, nodes_to_delete, axis = 1)
879+
879880
subgraph.graph = graph
880881
subgraph.reconstitute_dpath(subgraph.get_graph_edges())
881-
882+
882883
return subgraph
883884

884885
# Returns a string representation of the graph.

0 commit comments

Comments
 (0)