Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Network Science with Python and NetworkX Quick Start Guide

You're reading from   Network Science with Python and NetworkX Quick Start Guide Explore and visualize network data effectively

Arrow left icon
Product type Paperback
Published in Apr 2019
Publisher Packt
ISBN-13 9781789955316
Length 190 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
 Platt Platt
Author Profile Icon Platt
Platt
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Title Page
Copyright and Credits
Dedication
About Packt Contributors Preface 1. What is a Network? FREE CHAPTER 2. Working with Networks in NetworkX 3. From Data to Networks 4. Affiliation Networks 5. The Small Scale - Nodes and Centrality 6. The Big Picture - Describing Networks 7. In-Between - Communities 8. Social Networks and Going Viral 9. Simulation and Analysis 10. Networks in Space and Time 11. Visualization 12. Conclusion 1. Appendix 2. Other Books You May Enjoy

Adjacency matrices

A matrix is a way of describing pairwise relationships. A matrix looks like a grid of numbers, as in the following example:

┌           ┐
│ 0 1 42 │
│ 0.5 -3 1 │
└ ┘

The preceding matrix contains six entries, organized in two rows and three columns. A matrix can have any number of rows or columns, but they are always rectangular. A matrix with two rows and three columns is described as a 2 x 3 matrix. If the entire matrix is called A, then the element at row i and column j is called Ai,j. So, in the preceding example, A2,1 = 0.5.

One way to represent a graph as a matrix is to place the weight of each edge in one element of the matrix (or a zero if there is no edge). So, an edge from v3, to v1 with a weight of 37 would be represented by A3,1 = 37, meaning the third row has a 37 in the first column. This representation is called an adjacency matrix.

With a little thought, it can be shown that adjacency matrices are always square. The number of rows is the number of columns is the number of vertices. Similarly, there is nothing saying that Ai,j has to be the same as Aj,i, so adjacency matrices can easily represent a directed graph. For an undirected graph, Ai,j always equals Aj,i, so the matrix is symmetric across one diagonal.

As an example, consider this network from Chapter 1, What is a Network?:


The corresponding adjacency matrix is as follows:

┌           ┐
│ 0 3 0 0 0 │
│ 3 0 5 0 9 │
│ 0 5 0 0 1 │
│ 0 0 0 0 6 │
│ 0 9 1 6 0 │
└ ┘

Matrices are more than just grids of numbers though! There are many mathematical operations that can be used to manipulate and combine matrices. For example, addition can be defined for two matrices by adding the elements at the same row and column. These operations can correspond to meaningful network processes. One such operation is the transpose, which exchanges Ai,j with Aj,i. The transpose of A is denoted as AT and corresponds to reversing the direction of all edges.

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
Visually different images