Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot NetworkX Graph with numpy array error

I have my adjacency matrix as a numpy array and would like to plot it as a simple undirected graph using NetworkX but I keep running into this error: AttributeError: module 'scipy.sparse' has no attribute 'coo_array'

I'm following this: Plot NetworkX Graph from Adjacency Matrix in CSV file particular answer and could not get it to work. The only difference is that my adjacency matrix is rather huge with around 30000 columns

This is my graph drawing code:

G = nx.from_numpy_matrix(np.matrix(adj_mtx_np), create_using=nx.DiGraph)
nx.draw(G)
plt.show()

My scipy version is 1.8.0

like image 916
yxx Avatar asked Jun 08 '26 13:06

yxx


2 Answers

downgrade networkx to 2.6.3 and it solved this problem for me.

like image 196
hiroki Avatar answered Jun 10 '26 03:06

hiroki


Upgrade both scipy and networkx and it worked for me.

pip install --upgrade scipy networkx
like image 39
lyh458 Avatar answered Jun 10 '26 03:06

lyh458



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!