Reputation: 1
I am asking to create an adjacency matrix from a random graph. I really have no idea how to do it, the only way I knew was to build adjacency matrix through graph and vertex.
def adjacency_matrix(n,p)
The n is number of vertex and the p is the probability of there is an edge between 2 vertex.
Upvotes: 0
Views: 846
Reputation: 8801
You can take a look at NetworkX package. You can use the function gnp_random_graph for your purpose. It has the following parameters:
n (int) – The number of nodes.
p (float) – Probability for edge creation.
seed (integer, random_state, or None (default)) – Indicator of random number generation state. See Randomness.
directed (bool, optional (default=False)) – If True, this function returns a directed graph.
import networkx as nx
n = 20
p = 0.3
G = nx.generators.random_graphs.gnp_random_graph(n, p)
nx.draw(G)
Upvotes: 1