Putting a Graph in Numeric Format
Precision is an important part of using algorithms. Even though too much preci-
sion hides the overall pictures from humans, computers thrive on detail. Often,
the more detail you can provide, the better the results you receive. However, the
form of that detail is important. To use certain algorithms, the data you provide
must appear in certain forms or the result you receive won’t make sense (it will
contain errors or have other issues).
Fortunately, NetworkX provides a number of functions to convert your graph into
forms that other packages and environments can use. These functions appear at
http://networkx.readthedocs.io/en/stable/reference/convert.html
. The
following sections show how to present graph data as a NumPy (
http://www.
numpy.org/
) matrix, SciPy (
https://www.scipy.org/
) sparse representation,
and a standard Python list. You use these presentations as the book progresses to
work with the various algorithms. (The code in the following sections appears in
the
A4D; 08; Graph Conversion.ipynb
file and relies on the graph you created
in the “Counting edges and vertexes” section of the chapter.)
170
PART 3
Do'stlaringiz bilan baham: |