AttributeError in NetworkX, module has no max_clique attribute [closed]

会有一股神秘感。 提交于 2020-01-20 07:49:26

问题


like said in the title I have an attribute error. Here is my code:

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)   

for information the reading line is a Matrix created by another script:

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

Download it for testing!

Have you a solution? Thks


回答1:


The docs are a bit ambiguous about where this resides but the following worked for me:

In [4]:

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


来源:https://stackoverflow.com/questions/27483092/attributeerror-in-networkx-module-has-no-max-clique-attribute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!