Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:定向网络中的平均出度。为什么卡住了?_Python_Numpy_Networkx - Fatal编程技术网

Python:定向网络中的平均出度。为什么卡住了?

Python:定向网络中的平均出度。为什么卡住了?,python,numpy,networkx,Python,Numpy,Networkx,这是我的第一篇文章;我是一个初级python用户。我在几层字典中建立了一个定向网络(按城镇、性别等编入索引)。我只想计算自我的平均值和超度标准差,以性别和城镇分开。这看起来应该很简单,但我发现自己陷入了困境——我认为问题在于对象类型为list/array,但我无法理解它。非常感谢你的帮助。如果需要更多的细节,请告诉我。非常感谢 下面是有问题的代码部分(读取了边缘列表,构建了网络字典,没有问题): 如果不计算输入(本例中输入很复杂),其他人就无法运行您发布的代码,因此很难进行调试。请考虑在将来提交

这是我的第一篇文章;我是一个初级python用户。我在几层字典中建立了一个定向网络(按城镇、性别等编入索引)。我只想计算自我的平均值和超度标准差,以性别和城镇分开。这看起来应该很简单,但我发现自己陷入了困境——我认为问题在于对象类型为list/array,但我无法理解它。非常感谢你的帮助。如果需要更多的细节,请告诉我。非常感谢

下面是有问题的代码部分(读取了边缘列表,构建了网络字典,没有问题):


如果不计算输入(本例中输入很复杂),其他人就无法运行您发布的代码,因此很难进行调试。请考虑在将来提交一个最小的例子来重现您的问题。除此之外,您可能会发现<代码> NUMPY。您可以使用
out\u degree.mean()
计算平均值,使用
out\u degree.std()
计算标准偏差,等等。作为一般注释,有许多Python软件包是专门为处理图形而设计的,例如。。。这些库具有计算网络摘要统计信息的有效方法,从长远来看,这可能会为您节省大量时间和精力。
def town_stats(Dictionary_of_Networks, all_town_nos, all_wave_groups, all_sex_types):

    for vn in all_town_nos:

        for vw in all_wave_groups:

            for vs in all_sex_types:

                if vw=="EGOS":

                    out_values = D[vn][vw][vs].out_degree().values() 
                    #only want to calculate outdegree for EGOS 
                    out_degree=np.array(out_values)
                    avgoutdegree=out_degree/(D[vn][vw][vs].number_of_nodes()) 
                    #I'd like a single number for the mean outdegree for each town for  
                    #males, and another mean for each town for females.
                    avg_outdegreelist=list(avgoutdegree) 
                    #how to fix-> don't want list just a single number for each town. 
                    sd_outdegree = np.std(out_degree)

                print "  Network number %d type %s: %d nodes and %d edges. Average   
                outdegree: %r" % (vn, vs, D[vn][vw][vs].number_of_nodes(), D[vn][vw] 
                [vs].number_of_edges(), avg_outdegreelist) 
                print ""