-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Remove specific edge from MultiDiGraph #4478
Comments
For MultiGraph, the How do you do that? Creating the edge key has to happen when you create the edge. By default the edge keys are integers starting at 0 and incrementing for each edge between that pair of nodes. If you don't know the class for the edge when you construct the multigraph, you can convert one MultiGraph with edge attribute "class" to a MultiGraph with both edge attribute class, and identical edge key as follows: MH = nx.MultiGraph((u, v, c, {"class": c, "old_key": k}) for u, v, k, c in MG.edges(keys=True, data="class")) (actually, you don't need the If your "class" attribute is not unique within a pair of nodes, you can't use that value as an edge key. MG.remove_edges_from((u, v, k) for u, v, k, c in MG.edges(keys=True, data="class") if c == 12) That might remove more than one edge -- or no edges depending on which have attribute class==12. |
The |
I think this one has been sufficiently answered and the relevant info is in the docstring. This should be further bolstered by #5699. I'm going to close this but if the issue persists please feel free to reopen. |
Hi,
I am using MultiDiGraph and would like to remove a particular edge with particular class from node
u
tov
. That is, for example, for a graph as such:I would like to remove the edge (1, 2, {"class": 12}) while leaving the other edge from 1 to 2 unchanged.
Is it possible to do this? I looked at
remove_edge
but that seems to require that the edge attributes have different classification names, and that if I put multiple edges under the same classification name, it would remove them all.I have edges with weights, and ideally I would be able to assign these attributes without a particular class label but so far I don't seem to be able to do that.
The text was updated successfully, but these errors were encountered: