NetworkX中的AttributeError,模块没有max_clique属性

时间:2014-12-15 11:32:53

标签: python networkx

像标题中说的那样,我有一个属性错误。 这是我的代码:

from sympy import *
import numpy as np
import networkx as nx

G=nx.Graph()
with open ("testing.txt", "r") as myfile:
   Matrice=eval(myfile.readline())
   Matnum = np.array(np.array(Matrice))
   Matnum = Matnum.astype(np.int, copy=False)
   G.add_node(Matnum.shape[1])
   for i in range(0,Matnum.shape[1]):
      for j in range(i+1,Matnum.shape[1]):
         if Matnum[i,j] == 1:
            G.add_edge(i,j)
   print nx.max_clique(G)   

有关信息,读取行是由另一个脚本创建的Matrix:

Matrix([[1, 1, 1, 0, 0, ....... 0, 0, 1, 0, 1]])

Download it for testing!

你有解决方案吗? THKS

1 个答案:

答案 0 :(得分:8)

文档对于它所在的位置有点模棱两可,但以下内容对我有用:

In [4]:

G = nx.complete_graph(4)
from networkx.algorithms.approximation import clique
clique.max_clique(G)
Out[4]:
{0, 1, 2, 3}