16

A is co occurrence dataframe. Why it shown 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)

3 Answers 3

17

It was updated to nx.from_numpy_array(A)

Sign up to request clarification or add additional context in comments.

Comments

17

In networkx 3.0 the changelog shows the following "Remove to_numpy_matrix & from_numpy_matrix (#5746)" https://networkx.org/documentation/stable/release/release_3.0.html

You have to downgrade networkx or use G=nx.from_numpy_array(A) instead. https://networkx.org/documentation/stable/reference/readwrite/matrix_market.html

1 Comment

For those who may be interested, we can also utilize the to_numpy_array function. It's useful to get the adjacency matrix from causalnex: adj_matrix = nx.to_numpy_array(sm)
6

You can use G = nx.DiGraph(np.array(A)) instead of G = nx.from_numpy_matrix(np.array(A), create_using=nx.Graph)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.