邻接矩阵不返回所有有向图连接

问题描述

我的目标是构建一个代码,给定一个邻接矩阵,返回一个有向图。 我写了这个片段:

 fetch('http://localhost:3000/features,{
      method: 'GET',headers: {
        'Accept': 'application/json','Content-Type': 'application/json'
      }
    }).then(response => response.json())
    .then(data => {
      var user = data[user];
})

我期待最后一个命令会返回我:

>>> import networkx as nx
>>> import numpy as np
>>> G = nx.DiGraph()
>>> arr = np.array([[1,1],[1,0]])
>>> G = nx.from_numpy_array(arr)
>>> list(G.nodes)
    [0,1]
>>> list(G.edges)
    [(0,0),(0,1)]

我缺少什么?

解决方法

这会产生你想要的:

arr = np.array([[1,1],[1,0]])
G = nx.from_numpy_array(arr,create_using=nx.DiGraph)
list(G.nodes) # [0,1]
list(G.edges) # [(0,0),(0,1),(1,0)]