Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to use scipy.sparse._csr.csr_matrix to init a graph. #771

Open
Vimos opened this issue May 10, 2024 · 1 comment
Open

Failed to use scipy.sparse._csr.csr_matrix to init a graph. #771

Vimos opened this issue May 10, 2024 · 1 comment

Comments

@Vimos
Copy link

Vimos commented May 10, 2024

Describe the bug
A clear and concise description of what the bug is.

Failed to use scipy.sparse._csr.csr_matrix to init a graph.

Traceback (most recent call last):
  File "/home/vimos/diffusion_for_train.py", line 78, in <module>
    x, y = diffusion_inverse_pairs(adj, seeds, args.diffusion_model)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vimos/diffusion_for_train.py", line 18, in diffusion_inverse_pairs
    G = Graph.Adjacency(adj_matrix)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vimos/anaconda3/lib/python3.11/site-packages/igraph/io/adjacency.py", line 54, in _construct_graph_from_adjacency
    return _graph_from_sparse_matrix(cls, matrix, mode=mode, loops=loops)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vimos/anaconda3/lib/python3.11/site-packages/igraph/sparse_matrix.py", line 104, in _graph_from_sparse_matrix
    edges.extend([(i, j)] * n)
                 ~~~~~~~~~^~~
TypeError: can't multiply sequence by non-int of type 'numpy.float32'

To reproduce
Steps or minimal example code to reproduce the problem.

If you are confident that the issue is not in the Python interface but in the
C core of igraph, please add it to the main igraph repo
instead.

If you are unsure, feel free to add your issue here - we will transfer it to
the main igraph repo if the root cause is
in the C core of igraph.

Version information
Which version of python-igraph are you using and where did you obtain it?

git+https://github.com/igraph/python-igraph@develop

@ntamas
Copy link
Member

ntamas commented May 10, 2024

Try calling Graph.Adjacency(adj_matrix.astype(numpy.int32)) instead. Your matrix contains floating-point numbers; igraph tries to interpret the entries of the matrix as edge multiplicities, which are supposed to be integers. Alternatively, if you want a weighted matrix, use Graph.Weighted_Adjacency() instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants