Algorithms For Dummies


Exploring the World of Graphs



Download 7,18 Mb.
Pdf ko'rish
bet301/651
Sana15.07.2021
Hajmi7,18 Mb.
#120357
1   ...   297   298   299   300   301   302   303   304   ...   651
Bog'liq
Algorithms

 Exploring the World of Graphs

Adding a graph to a matrix

Using NetworkX, you can easily move your graph to a NumPy matrix and back 

again as needed to perform various tasks. You use NumPy to perform all sorts of 

data manipulation tasks. By analyzing the data in a graph, you might see patterns 

that wouldn’t ordinarily be visible. Here’s the code used to convert the graph into 

a matrix that NumPy can understand:

import networkx as nx

import matplotlib.pyplot as plt

%matplotlib inline

AGraph = nx.Graph()

Nodes = range(1,6)

Edges = [(1,2), (2,3), (3,4), (4,5), (1,3), (1,5), (1,6)]

AGraph.add_nodes_from(Nodes)

AGraph.add_edges_from(Edges)

nx.to_numpy_matrix(AGraph)

matrix([[ 0.,  1.,  1.,  0.,  1.,  1.],

        [ 1.,  0.,  1.,  0.,  0.,  0.],

        [ 1.,  1.,  0.,  1.,  0.,  0.],

        [ 0.,  0.,  1.,  0.,  1.,  0.],

        [ 1.,  0.,  0.,  1.,  0.,  0.],

        [ 1.,  0.,  0.,  0.,  0.,  0.]])

The resulting rows and columns show where connections exist. For example, 

there is no connection between node 1 and itself, so row 1, column 1, has a 0 in it. 

However, there is a connection between node 1 and node 2, so you see a 1 in row 1, 

column 2, and row 2, column 1 (which means that the connection goes both ways 

as an undirected connection).

The size of this matrix is affected by the number of nodes (the marix has as many 

rows and columns as nodes), and when it grows huge, it has many nodes to rep-

resent because the total number of cells is the square of the number of nodes. For 

instance, you can’t represent the Internet using such a matrix because a conser-

vative estimate calculates that at 10^10 websites, you’d need a matrix with 10^20 

cells to store its structure, something impossible with the present computing 

capacity.



CHAPTER 8


Download 7,18 Mb.

Do'stlaringiz bilan baham:
1   ...   297   298   299   300   301   302   303   304   ...   651




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2025
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish