ctwayen / GNN-Points-Cloud

4 stars 2 forks source link

Question about drawing graph #2

Open chouchouxia opened 3 years ago

chouchouxia commented 3 years ago

Hello ,when I try to run "Visual sample note book", I came across a question:

when I run the following code: A = graph_construct.graph_construct_radius(test_1000, 0.3); G = visual.graph(A); visual.draw_graph(G, test_1000);

I got an error like this:

`TypeError Traceback (most recent call last)

in 1 A = graph_construct.graph_construct_radius(test_1000, 0.3) ----> 2 G = visual.graph(A) 3 visual.draw_graph(G, test_1000) E:\test\deepng\GNN-Points-Cloud-main\src\visual.py in graph(edges) 8 edge.append((edges[0][i], edges[1][i])) 9 G = nx.Graph() ---> 10 G.add_edges_from(edge) 11 return G 12 D:\Anaconda\envs\CS224W\lib\site-packages\networkx\classes\graph.py in add_edges_from(self, ebunch_to_add, **attr) 940 else: 941 raise NetworkXError(f"Edge tuple {e} must be a 2-tuple or 3-tuple.") --> 942 if u not in self._node: 943 if u is None: 944 raise ValueError("None cannot be a node") TypeError: unhashable type: 'numpy.ndarray'` I try to modify the code as : `A = graph_construct.graph_construct_radius(test_1000, 0.3); G = visual.graph(A[0]); visual.draw_graph(G, test_1000);` and it works well. But in this way, I ignored the weights in A[1]. So I am confused about whether I need to construct the graph with weight and whether the errors is due to networkx or matplotlib version. my environment: h5py 3.4.0 pypi_0 pypi matplotlib 3.4.3 pypi_0 pypi matplotlib-inline 0.1.2 pyhd3eb1b0_2 networkx 2.6.2 pypi_0 pypi ninja 1.7.2 0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free notebook 6.1.5 py37haa95532_0 numpy 1.20.3 py37ha4e8547_0 numpy-base 1.20.3 py37hc2deb75_0 oauth2client 4.1.3 pypi_0 pypi ogb 1.3.1 pypi_0 pypi pandas 1.3.2 pypi_0 pypi python 3.7.11 h6244533_0 python-dateutil 2.8.2 pyhd3eb1b0_0 python-louvain 0.15 pypi_0 pypi pytorch 1.7.1 py3.7_cpu_0 [cpuonly] pytorch scikit-learn 0.24.2 pypi_0 pypi scipy 1.7.1 pypi_0 pypi send2trash 1.5.0 pyhd3eb1b0_1 setuptools 52.0.0 py37haa95532_0 six 1.12.0 pypi_0 pypi sqlite 3.36.0 h2bbff1b_0 terminado 0.9.4 py37haa95532_0 testpath 0.5.0 pyhd3eb1b0_0 threadpoolctl 2.2.0 pypi_0 pypi tk 8.6.10 he774522_0 torch-geometric 1.7.2 pypi_0 pypi torch-scatter 2.0.7 pypi_0 pypi torch-sparse 0.6.8 pypi_0 pypi torchaudio 0.7.2 py37 pytorch torchvision 0.8.2 py37_cpu [cpuonly] pytorch tornado 6.0 pypi_0 pypi tqdm 4.62.1 pypi_0 pypi
ctwayen commented 2 years ago

Interesting. I will lool this up and give u a answer later

ctwayen commented 2 years ago

Hi. The code in the visual_sample notebook actually used the old version of the function construct graph and at that time the function only returns edges instead of both edges and weights. So what you are doing (pass A[0]) is right since A[1] is the weight of the edges and should not be passed into draw() function. Thank you for finding this bug!

BTW, if you find this repo helpful. Please star it. It will help a lot