user18756599
user18756599

Reputation:

Getting adjacency matrix from random graph in Python

The following code generates a random graph. How do I obtain adjacency matrix for each graph?

import networkx as nx

n = 10
p = 0.9

G = nx.generators.random_graphs.gnp_random_graph(n, p)
nx.draw(G)

Upvotes: 1

Views: 1175

Answers (1)

mcsoini
mcsoini

Reputation: 6642

See here:

A = nx.adjacency_matrix(G)
A.toarray()

Upvotes: 4

Related Questions