Creating directed and weighted networks
Simple networks, such as those described in the previous recipes, are useful for describing networks where the direction of an edge is unimportant and where the edges carry equal weight. In practice, most networks carry additional information, such as weights or directions.
In this recipe, we will create a directed and weighted network and explore some of the basic properties of such networks.
Getting ready
For this recipe, we will need the NetworkX package, imported under the nx
alias (as usual), the Matplotlib pyplot
module imported as plt
, and the NumPy package imported as np
.
How to do it...
The following steps outline how to create a directed network with weights, as well as how to explore some of the properties and techniques we discussed in the previous recipes:
- To create a directed network, we can use the
DiGraph
class from NetworkX rather than the simpleGraph
class:G = nx.DiGraph()
- As usual, we must add nodes...