ENH: Add format parameter to adjacency_matrix#8545
Open
toroleapinc wants to merge 1 commit intonetworkx:mainfrom
Open
ENH: Add format parameter to adjacency_matrix#8545toroleapinc wants to merge 1 commit intonetworkx:mainfrom
toroleapinc wants to merge 1 commit intonetworkx:mainfrom
Conversation
Add a 'format' parameter to adjacency_matrix() to allow specifying the sparse format of the returned matrix, consistent with to_scipy_sparse_array(). This includes support for 'dense' format which returns a numpy ndarray. The adjacency_matrix function is a thin wrapper around to_scipy_sparse_array but previously didn't expose the format parameter. This change simply passes it through. Closes networkx#7980 (partial: adjacency_matrix only) Signed-off-by: edvatar <88481784+toroleapinc@users.noreply.github.com>
rossbar
reviewed
Mar 3, 2026
Contributor
There was a problem hiding this comment.
The kwarg should be made keyword-only and a test is needed.
Author
|
@rossbar Thanks for the feedback! You're absolutely right about both points:
I'll implement these changes and push an update. Thanks for the clear guidance! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor
6940
that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
formatparameter toadjacency_matrix()to allow specifying the sparse format of the returned matrix (or'dense'for a numpy ndarray), consistent withto_scipy_sparse_array().Partial fix for #7980.
Changes
adjacency_matrix()is a thin wrapper aroundto_scipy_sparse_array()but previously didn't expose theformatparameter. This change simply passes it through.Example