Python 带权重的igraph初始化
如何使用权重初始化igraph 这就是我所拥有的Python 带权重的igraph初始化,python,igraph,vertices,edges,Python,Igraph,Vertices,Edges,如何使用权重初始化igraph 这就是我所拥有的 cr = csv.reader(open("atlas.csv","rb")) mapping = {} for row in cr: if int(row[2]) == 1: continue source = int(row[0]) target = int(row[1]) if source in mapping: list = mapping[source]
cr = csv.reader(open("atlas.csv","rb"))
mapping = {}
for row in cr:
if int(row[2]) == 1:
continue
source = int(row[0])
target = int(row[1])
if source in mapping:
list = mapping[source]
list.append(target)
else:
mapping[source] = [target]
print mapping
G = Graph(edges = [(v, a) for v in mapping.keys() for a in mapping[v]])
print G
我尝试使用
edges=(v,a,w)
添加权重,但没有效果。根据文档,您可以使用以下方法:
如果你有一个加权图,你可以
使用第三个项目包含边的权重的项目
将边缘属性设置为“重量”
或[“重量”]
您还可以将权重
参数设置为真
:
权重
-指定图形权重的替代方法。如果
您将权重设置为true,并且未给出边缘属性
,它将
假设edge\u attrs
是[“weight”]
并且igraph
将解析第三个属性
元素从每个项目转换为边权重。如果将权重设置为
字符串,则假定edge\u attrs
仅包含该字符串,
而igraph
将在该属性中存储边权重
我已经提出了一个解决办法,希望这就是你的意思。谢谢