[英]Multi Directed Graph in NetworkX not loading
I am trying to load in a Multi Directed Graph in NetworkX for a programming assignment with a given txt file, but it is not working.我正在尝试在 NetworkX 中加载多向图以使用给定的 txt 文件进行编程分配,但它不起作用。 There are no errors, but when I graph the graph and when I do a quick check check to see how many nodes/edges there are it returns 0 for both - which leads me to believe that it is just not loading in the file into the graph at all.
没有错误,但是当我绘制图形并进行快速检查以查看有多少个节点/边时,两者都返回 0 - 这让我相信它只是没有将文件加载到图表。 Here is my code:
这是我的代码:
import networkx as nx
def answer_one():
# Your Code Here
G = nx.read_edgelist('email_network.txt', delimiter='\\t', data=[('time', int)], create_using=nx.MultiDiGraph())
return G
answer_one()
Here is a bit of the file I am trying to read in (email_network.txt):这是我试图读取的一些文件(email_network.txt):
#Sender Recipient time
1 2 1262454010
1 3 1262454010
1 4 1262454010
1 5 1262454010
1 6 1262454010
1 7 1262454010
1 8 1262454010
1 9 1262454010
1 10 1262454010
1 11 1262454010
1 12 1262454010
1 13 1262454010
1 14 1262454010
1 15 1262454010
I looked at Python Reading from a file to create a weighted directed graph using networkx and https://networkx.org/documentation/networkx-1.9/reference/generated/networkx.readwrite.edgelist.read_edgelist.html?highlight=read_edgelist to try to find what parameters I am using wrong but neither of them were that helpful.我查看了Python 从文件中读取以使用 networkx和https://networkx.org/documentation/networkx-1.9/reference/generated/networkx.readwrite.edgelist.read_edgelist.html?highlight=read_edgelist 创建加权有向图来尝试找出我使用错误的参数,但它们都没有帮助。
Can anyone help me figure out what I am doing wrong/how to load in the file correctly?谁能帮我弄清楚我做错了什么/如何正确加载文件? Thank you :)
谢谢 :)
更新:我找到了,它是G = nx.read_edgelist('email_network.txt', edgetype=int, data=(('weight', int),), create_using=nx.MultiDiGraph())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.