Add option for biadjacency_matrix to be returned as a dense NumPy array#7973
Add option for biadjacency_matrix to be returned as a dense NumPy array#7973dschult merged 5 commits intonetworkx:mainfrom michaelweinold:main
biadjacency_matrix to be returned as a dense NumPy array#7973Conversation
|
This seems like a good idea to me! Note that @michaelweinold I'm curious--what's the performance difference between your code for creating a numpy array vs using the original code with
The other functions I found that return scipy sparse arrays but don't have a way to specify the format are |
|
Hmm... that's odd - I could have sworn that I tried to pass
I believe the speedup is negligible - I can roll back the changes to the function itself and simply leave the updated docstring with the I would very much like to adapt the |
Thanks for pointing this out @eriknw - I really like this idea! AIUI it's basically just taking advantage of a (new-ish?) feature in scipy to provide users with dense arrays with zero code change! |
|
Depending on your needs, you could try I think to update |
|
...I removed the condition (negligible speedup, as mentioned above). The only change now is the |
rossbar
left a comment
There was a problem hiding this comment.
LGTM thanks @michaelweinold
We could also consider adding a test, but presumably the "dense" option is sufficiently covered in scipy's test suite so it's not absolutely critical.
...sometimes my biadjacency matrices are not sparse. I therefore believe that it would be helpful to have an option of getting the matrix directly as a dense array, rather than just a SciPy sparse array.
I have added a
formatoption"dense"- otherwise, the function remains the same.Do let me know if this warrants a separate test case somewhere in
networkx/algorithms/bipartite/tests/test_basic.py.This would be my first NetworkX contribution 😇