Created
September 6, 2012 06:03
-
-
Save satomacoto/3651907 to your computer and use it in GitHub Desktop.
NetworkX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import networkx as nx | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# Zachary's Karate Club graph | |
G = nx.karate_club_graph() | |
# to directed | |
G = G.to_directed() | |
# draw & show | |
nx.draw(G, pos=nx.spring_layout(G)) | |
#plt.show() | |
# dumps to json | |
import networkx.readwrite.json_graph as jsg | |
s = jsg.dumps(G) | |
#G = jsg.loads(s) | |
print s | |
# to numpy matrix | |
A = nx.to_numpy_matrix(G) | |
np.savetxt("myfile.txt", A) | |
A = np.genfromtxt("myfile.txt") | |
print A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment