Reputation: 50
I want to remove an edge attribute from a Graph object in python-igraph
. The equivalent igraph R function is cleverly called delete_edge_attr
. I haven't been able to find an equivalent function/method in Python... is there one?
If not, is there another way to do it? (I tried a simple g.es['edge_attr']= []
but this didn't work).
Example Code
g = ig.Graph.Tree(10, 2) #Generate random graph
g_betweenness = g.betweenness() #Calculate betweenness for graph
g['betweenness'] = betweenness #Assign betweenness as edge attribute
print(g.attributes())
g['betweenness'] = [] #Attempt to remove betweenness edge attribute (incorrect)
print(g.attributes())
Output
['betweenness']
['betweenness']
Desired output
['betweenness']
[]
Upvotes: 2
Views: 985
Reputation: 11420
You might not be able to set it to an empty array, but your intuition about directly altering the EdgeSequence
was already pretty good. You can simply delete the argument with Python's internal del()
, I've included a minimal example below:
import igraph
# minimal graph
G = igraph.Graph()
G.add_vertices(2)
G.add_edge(0,1)
# add your property
G.es['betweenness'] = [1]
# print edge attribute (note the difference to your example)
print(G.es.attribute_names())
# output: ['weight']
# delete argument
del(G.es['weight'])
# print again
print(G.es.attribute_names())
# output: []
Upvotes: 1