What is the most efficient graph data structure in Python?
"""
Create an G{n,m} random graph with n nodes and m edges
and report some properties.
This graph is sometimes called the Erd##[m~Qs-Rényi graph
but is different from G{n,p} or binomial_graph which is also
sometimes called the Erd##[m~Qs-Rényi graph.
"""
__author__ = """Aric Hagberg (hagberg@lanl.gov)"""
__credits__ = """"""
# Copyright (C) 2004-2006 by
# Aric Hagberg
# Dan Schult
# Pieter Swart
# Distributed under the terms of the GNU Lesser General Public License
# http://www.gnu.org/copyleft/lesser.html
from networkx import *
import sys
n=10 # 10 nodes
m=20 # 20 edges
G=gnm_random_graph(n,m)
# some properties
print "node degree clustering"
for v in nodes(G):
print v,degree(G,v),clustering(G,v)
# print the adjacency list to terminal
write_adjlist(G,sys.stdout)
Tags: python performance graph-theory data-structures
Source: By bgoncalves as answer to the question
This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 3.0
Related code-snippets:
- How can I get the value of in a loop?
- Anatomy of a memory leak -'memory leak'
- How can I find the full path of a font from its display name on a Mac?
- How do I see preview JPEG file of PDF on Windows?
- How do you iterate over a result set of data?
- What is the most efficient code for 10000 prime numbers?
- Redefining an attribute in Python with an index in array of objects using 'in'. If no object is found in an array of objects then it is not correct.
- How can I create an object instance from a Type?
- MySQL and Python are both well written programmers.
- How can I use itertools.groupby()?
- How can we add a method to an existing Object Instance?
- How is database indexing used?
- How can we write binary literals in Python?
- How do I make a list of items that does not need the user to press [enter]?
- Which OS am I running on and how can I adapt it?