15.08.2015 Views

Introduction to the Modeling and Analysis of Complex Systems

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

316 CHAPTER 15. BASICS OF NETWORKSLet’s work on a simple example. You can create your own adjacency list in a regularspreadsheet (such as Micros<strong>of</strong>t Excel or Google Spreadsheet) <strong>and</strong> <strong>the</strong>n save it in a “csv”format file (Fig. 15.6). In this example, <strong>the</strong> adjacency list says that John is connected <strong>to</strong>Jane <strong>and</strong> Jack; Jess is connected <strong>to</strong> Josh <strong>and</strong> Jill; <strong>and</strong> so on.Figure 15.6: Creating an adjacency list in a spreadsheet.You can read this file by using <strong>the</strong> read_adjlist comm<strong>and</strong>, as follows:Code 15.14: read-adjlist.pyfrom pylab import *import networkx as nxg = nx.read_adjlist(’myNetworkData.csv’, delimiter = ’,’)nx.draw(g, with_labels = True)show()The read_adjlist comm<strong>and</strong> generates a network by importing a text file that lists <strong>the</strong>names <strong>of</strong> nodes in <strong>the</strong> adjacency list format. By default, it considers spaces (’ ’) a separa<strong>to</strong>r,so we need <strong>to</strong> specify <strong>the</strong> delimiter = ’,’ option <strong>to</strong> read <strong>the</strong> CSV (comma separated

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!