[Numpy-discussion] numpy array in networkx graph?

2012-06-13 Thread bob tnur
I have M is numpy matrix with 0's 1's. I want to color the nodes with different colors. can anyone give me a hint on the following code? import network as nx import pylab as plt G=nx.Graph(M) # M is numpy matrix ,i.e:type(M)=numpy.ndarray for i in xrange(len(M)): tt=P[i,:].sum() if

[Numpy-discussion] numpy array in networkx graph?

2012-06-12 Thread bob tnur
can anyone give me a hint on the following code? import network as nx import pylab as plt G=nx.Graph(M) # M is numpy matrix ,i.e:type(M)=numpy.ndarray for i in xrange(len(M)): tt=P[i,:].sum() if tt==1: G.add_node(i,color='blue') elif tt==2:

Re: [Numpy-discussion] numpy array in networkx graph?

2012-06-12 Thread Brett Olsen
This seems to work: import networkx as nx import pylab import numpy as N M = N.random.random((10, 10)) G = nx.Graph(M) node_colors = [] for i in xrange(len(M)): if M[i,0] 0.5: node_colors.append('white') else: node_colors.append('blue') nx.draw(G, node_color=node_colors)