nx.adjacency_matrix return an error: a bug?

52 views
Skip to first unread message

Franck Kalala

unread,
Dec 2, 2022, 10:35:28 AM12/2/22
to networkx...@googlegroups.com
Dear Folk

Was try run this piece of code:
*************
    G = nx.Graph([(1, 1)])
A = nx.adjacency_matrix(G)
print(A.todense())

A.setdiag(A.diagonal() * 2)
print(A.todense())
****************
but I am having this error message. Seems nx.adjacency_matrix (), does not work. I wander if it is a bug.

Best

F


>>> import networkx as nx

>>> nx. __version__

'2.8.8'

>>> G = nx.Graph([(1, 1)])

>>> A = nx.adjacency_matrix(G)

<stdin>:1: FutureWarning: adjacency_matrix will return a scipy.sparse array instead of a matrix in Networkx 3.0.

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/Users/franckm/opt/anaconda3/lib/python3.9/site-packages/networkx/linalg/graphmatrix.py", line 173, in adjacency_matrix

    return nx.to_scipy_sparse_matrix(G, nodelist=nodelist, dtype=dtype, weight=weight)

  File "/Users/franckm/opt/anaconda3/lib/python3.9/site-packages/networkx/convert_matrix.py", line 1021, in to_scipy_sparse_matrix

    A = to_scipy_sparse_array(

  File "/Users/franckm/opt/anaconda3/lib/python3.9/site-packages/networkx/convert_matrix.py", line 923, in to_scipy_sparse_array

    A = sp.sparse.coo_array((d, (r, c)), shape=(nlen, nlen), dtype=dtype)

AttributeError: module 'scipy.sparse' has no attribute 'coo_array'



Ross Barnowski

unread,
Dec 2, 2022, 10:46:46 AM12/2/22
to networkx...@googlegroups.com
NetworkX >= v2.7 requires scipy >= 1.8. The exception you are seeing is because sparse *arrays* were added in scipy 1.8.

~Ross

--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/CAN%2BjCOoMgbL0yF-oDjNpYQWUGLYRZutWTc4qXeHT5QOKj87mCg%40mail.gmail.com.

Franck Kalala

unread,
Dec 2, 2022, 11:52:55 AM12/2/22
to networkx...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages