[SciPy-user] matrix construction

Stephen Walton stephen.walton at csun.edu
Fri Sep 24 16:24:08 EDT 2004


On Thu, 2004-09-23 at 08:29, William Griffin wrote:
> I'm trying to build an adjacency matrix (52*52)

Maybe this is so obvious that I'm missing what you're trying to do:

from string import *
from numarray import *
A=zeros((52,52))			# adjacency matrix
file=open('data')
for line in file.readlines():
   w = split(line)
   m = atoi(w[0])
   n = atoi(w[1])
   A[m, n] += 1

I've gotten in the habit of using m,n instead of i,j, by the way because
of i and j being the sqrt(-1) in MATLAB and Numeric/numarray,
respectively.

Now, does anyone have code to draw a connectivity graph from an
adjacency matrix like this?





More information about the SciPy-User mailing list