AttributeError:模块“networkx”没有属性“from_numpy_matrix”

Pra*_*nab 10 python graph networkx python-3.x

A 是共现数据框。为什么显示 AttributeError: module 'networkx' has no attribute 'from_numpy_matrix'

import numpy as np
import networkx as nx
import matplotlib
A=np.matrix(coocc)
G=nx.from_numpy_matrix(A)
Run Code Online (Sandbox Code Playgroud)

小智 13

在 networkx 3.0 中,更改日志显示以下“删除to_numpy_matrix& from_numpy_matrix(#5746)” https://networkx.org/documentation/stable/release/release_3.0.html

您必须降级networkx或使用G=nx.from_numpy_array(A)它。 https://networkx.org/documentation/stable/reference/readwrite/matrix_market.html


小智 5

您可以使用G = nx.DiGraph(np.array(A))代替G = nx.from_numpy_matrix(np.array(A), create_using=nx.Graph)


Ima*_*anB 4

已更新为nx.from_numpy_array(A)