Issue
I have a python-igraph and need to make two copies of it and change each of the copies without changing the other one. Right now I am doing it like this:
copy1 = fullGraph
copy2 = fullGraph
But it seems that this is not the correct way of doing it since whatever I change in copy1, the same thing happen to copy2 (like deleting an edge). I was wondering what is the best way to make a copy of the main graph.
Thanks
Solution
Assign statements do not copy objects in Python. You might want to use
copy.deepcopy()
function.
More details about copy.shallow()
and copy.deepcopy()
can be found in this answer
Also Graph
objects have inherited copy
method which makes a shallow copies. You can use it like:
copy1 = fullGraph.copy()
copy2 = fullGraph.copy()
Answered By - Alik
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.