Questions tagged [adjacency-matrix]

A means of representing which vertices (or nodes) of a graph are adjacent to which other vertices.

The adjacency matrix of a finite graph G on n vertices is the n×n matrix where the non-diagonal entry aij is the number of edges from vertex i to vertex j, and the diagonal entry aii, depending on the convention, is either once or twice the number of edges (loops) from vertex i to itself.

Undirected graphs often use the latter convention of counting loops twice, whereas directed graphs typically use the former convention.
There exists a unique adjacency matrix for each isomorphism class of graphs (up to permuting rows and columns), and it is not the adjacency matrix of any other isomorphism class of graphs.
In the special case of a finite simple graph, the adjacency matrix is a (0,1)-matrix with zeros on its diagonal.

If the graph is undirected, the adjacency matrix is symmetric.

The relationship between a graph and the eigenvalues and eigenvectors of its adjacency matrix is studied in spectral graph theory.

http://en.wikipedia.org/wiki/Adjacency_matrix

788 questions
143
votes
11 answers

What is better, adjacency lists or adjacency matrices for graph problems in C++?

What is better, adjacency lists or adjacency matrix, for graph problems in C++? What are the advantages and disadvantages of each?
magiix
  • 1,511
  • 2
  • 12
  • 11
35
votes
7 answers

Generating Symmetric Matrices in Numpy

I am trying to generate symmetric matrices in numpy. Specifically, these matrices are to have random places entries, and in each entry the contents can be random. Along the main diagonal we are not concerned with what enties are in there, so I have…
Ryan
  • 353
  • 1
  • 3
  • 5
30
votes
5 answers

How can I convert a two column array to a matrix with counts of occurences?

I have the following numpy array: import numpy as np pair_array = np.array([(205, 254), (205, 382), (254, 382), (18, 69), (205, 382), (31, 183), (31, 267), (31, 382), (183, 267), (183, 382)]) print(pair_array) #[[205…
13
votes
3 answers

Adjacency List and Adjacency Matrix in Python

Hello I understand the concepts of adjacency list and matrix but I am confused as to how to implement them in Python: An algorithm to achieve the following two examples achieve but without knowing the input from the start as they hard code it in…
Baraa
  • 667
  • 1
  • 8
  • 23
12
votes
2 answers

Python, Scipy: Building triplets using large adjacency matrix

I am using an adjacency matrix to represent a network of friends which can be visually interpreted as Mary 0 1 1 1 Joe 1 0 1 1 Bob 1 1 0 1 Susan 1 1 1 0 …
will
  • 225
  • 1
  • 7
12
votes
4 answers

How to create weighted adjacency list/matrix from edge list?

My problem is very simple: I need to create an adjacency list/matrix from a list of edges. I have an edge list stored in a csv document with column1 = node1 and column2 = node2 and I would like to convert this to a weighted adjacency list or a…
Milo
  • 155
  • 1
  • 1
  • 7
11
votes
1 answer

graphs representation : adjacency list vs matrix

I'm preparing for a coding interview, and was refreshing my mind on graphs. I was wondering the following : in all places I've seen, it is assumed that adjacency lists are more memory efficient than adjacency matrices for large sparse graphs, and…
nbonneel
  • 3,109
  • 4
  • 23
  • 36
10
votes
3 answers

Properly plotting large adjacency matrix in R

I've got a rather large (but quite sparse) adjacency matrix (500x500) that I am trying to visually represent. It seems to me that something akin to a force directed graph is my best bet and while trying to figure out the best way to implement this,…
Drofdarb
  • 159
  • 1
  • 9
10
votes
5 answers

Adjacency matrix in Python

I cannot find any clear explanation as to how to create an adjacency matrix in Python, with weights taken into consideration. I assume it should be relatively simple to create. I have the following matrix... 1 2 3 4 5 6 1 0 15 0 7…
buydadip
  • 7,310
  • 14
  • 63
  • 127
10
votes
1 answer

How to 'zero' out rows & columns in an array

I have a 2D array to represent a many-many mapping : 0 3 1 3 3 0 0 0 1 0 0 0 3 0 0 0 What is the quickest way to 'zero' out rows and column entries corresponding to a particular index in this array?
IUnknown
  • 7,639
  • 12
  • 43
  • 65
10
votes
5 answers

How can you make an adjacency matrix which would emulate a 2d grid

Basically just want to know what a good way to do this is in python, I have done this before with a kind of bruteforce way also in python but it just doesnt to be the intuitive way. So if anyone could help out it would be good.
10
votes
1 answer

Generate an Adjacency Matrix for a Weighted Graph

I am trying to implement Floyd-Warshall Algorithm. To do this it requires me to set up an adjacency matrix of a weighted graph. How would I go about doing this? I know the values and have attached a picture of the weighted graph. I have tried to…
JLott
  • 1,738
  • 3
  • 32
  • 53
9
votes
2 answers

using graph.adjacency() in R

I have a sample code in R as follows: library(igraph) rm(list=ls()) dat=read.csv(file.choose(),header=TRUE,row.names=1,check.names=T) # read .csv…
N D Thokare
  • 1,541
  • 5
  • 33
  • 56
8
votes
1 answer

How to compute the Topological Overlap Measure [TOM] for a weighted adjacency matrix in Python?

I'm trying to calculate the weighted topological overlap for an adjacency matrix but I cannot figure out how to do it correctly using numpy. The R function that does the correct implementation is from WGCNA…
O.rka
  • 24,289
  • 52
  • 152
  • 253
8
votes
3 answers

How to graph adjacency matrix using MATLAB

I want to create a plot showing connections between nodes from an adjacency matrix like the one below. gplot seems like the best tool for this. However, in order to use it, I need to pass the coordinate of each node. The problem is that I don't…
Charles Clayton
  • 13,212
  • 10
  • 73
  • 114
1
2 3
52 53