Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Network Science with Python and NetworkX Quick Start Guide

You're reading from  Network Science with Python and NetworkX Quick Start Guide

Product type Book
Published in Apr 2019
Publisher Packt
ISBN-13 9781789955316
Pages 190 pages
Edition 1st Edition
Languages
Author (1):
Edward L. Platt Edward L. Platt
Profile icon Edward L. Platt

Table of Contents (15) Chapters

Preface What is a Network? Working with Networks in NetworkX From Data to Networks Affiliation Networks The Small Scale - Nodes and Centrality The Big Picture - Describing Networks In-Between - Communities Social Networks and Going Viral Simulation and Analysis Networks in Space and Time Visualization Conclusion Other Books You May Enjoy Appendix

Diameter and mean shortest path

The size of a network can be quantified in several ways. In Chapter 5, The Small Scale – Nodes and Centrality, the distance between two nodes was defined as the length of the shortest path between them. With a way to measure distance, it becomes possible to define size based on that distance.

NetworkX provides several convenient functions for finding distances and shortest paths. The shortest paths between two particular nodes can be found using the all_shortest_paths() function:

list(nx.all_shortest_paths(G_karate, mr_hi, john_a))
[[0, 8, 33], [0, 13, 33], [0, 19, 33], [0, 31, 33]]

If you only need to know the distance, the shortest_path_length() function will provide that:

nx.shortest_path_length(G_karate, mr_hi, john_a)
2

On the other hand, the distance between all node pairs can be found using the shortest_path_length() function. This function...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}