igraph adjacency matrix python
#create graph
g = igraph.Graph([[1,2], [2,3], [0,3]])
#Returns the adjacency matrix of a graph.
g.get_adjacency()
#Returns the adjacency matrix of a graph as a SciPy CSR matrix.
g.get_adjacency_sparse()
igraph adjacency matrix python
#create graph
g = igraph.Graph([[1,2], [2,3], [0,3]])
#Returns the adjacency matrix of a graph.
g.get_adjacency()
#Returns the adjacency matrix of a graph as a SciPy CSR matrix.
g.get_adjacency_sparse()
adjacency matrix of a directed graph
/*adjacency matrix implementation of directed graph:
0---->1---|
| |---->4
|-> 2-->3-|
-------------------------------------------------*/
#include <iostream>
using namespace std;
#define v 5
void inti(int mat[][v])
{
for(int i=0;i<v;i++)
{
for(int j=0;j<v;j++)
{
mat[i][j]=0;
}
}
}
void addedge(int mat[][v],int start,int endvertix)
{
mat[start][endvertix]=1;
}
void printmat(int mat[][v])
{
for(int i=0;i<v;i++)
{
for(int j=0;j<v;j++)
{
cout<<mat[i][j]<<" ";
}
cout<<endl;
}
}
int main()
{
int array_in_graph[v][v];
inti(array_in_graph);
addedge(array_in_graph,0,1);
addedge(array_in_graph,0,2);
addedge(array_in_graph,0,3);
addedge(array_in_graph,1,3);
addedge(array_in_graph,1,4);
addedge(array_in_graph,2,3);
addedge(array_in_graph,3,4);
printmat(array_in_graph);
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us