Skip to content

Add example laplacian matrix #6168

Merged
MridulS merged 6 commits intonetworkx:mainfrom
paulitapb:add_example_laplacian_mat
Nov 17, 2022
Merged

Add example laplacian matrix #6168
MridulS merged 6 commits intonetworkx:mainfrom
paulitapb:add_example_laplacian_mat

Conversation

@paulitapb
Copy link
Copy Markdown
Member

No description provided.

matrix for each component.

>>> G = nx.graph_atlas(26) #This graph from the Graph Atlas has 2 connected components.
>>> print(nx.laplacian_matrix(G).todense())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using toarray would be preferable to todense here - we can also then get rid of the print and just rely on the array repr.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using toarray would be preferable to todense here - we can also then get rid of the print and just rely on the array repr.

Without the print there are some docs tests that failed due to differences in some OS. On Windows at the end of the array is added dtype=int32) but not on Ubuntu. Should I add the print back?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - I wasn't expecting that but I suppose makes sense given windows integer types.

I suppose the two options are to add the print back or add an explicit cast, e.g. toarray().astype(np.int64). Neither is ideal but both should be fine, so whatever you think is best!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The platform-specific printing is likely related to something in numpy itself, see numpy/numpy#22586.

In the meantime, the printing workaround seems fine to me!

@rossbar rossbar added the outreachy-review A temp label to help reviewers organize outreachy PRs for review label Nov 8, 2022
Copy link
Copy Markdown
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @paulitapb , just one code style nit that I took the liberty of pushing up (I think it should've been caught by blacken-docs in CI?). LGTM!

@MridulS MridulS merged commit d975b35 into networkx:main Nov 17, 2022
@jarrodmillman jarrodmillman added this to the networkx-3.0 milestone Dec 2, 2022
MridulS pushed a commit to MridulS/networkx that referenced this pull request Feb 4, 2023
* add example laplacian matrix

* Add example laplacian_matrix

* fix style

* add explicit example

* add print back

* Fix code style in example.

Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
cvanelteren pushed a commit to cvanelteren/networkx that referenced this pull request Apr 22, 2024
* add example laplacian matrix

* Add example laplacian_matrix

* fix style

* add explicit example

* add print back

* Fix code style in example.

Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

outreachy-review A temp label to help reviewers organize outreachy PRs for review

Development

Successfully merging this pull request may close these issues.

4 participants