[SciPy-user] matrix construction

Stephen Waterbury golux at comcast.net
Fri Sep 24 16:09:09 CDT 2004

Fernando Perez wrote:

> Just a slightly more 'pythonic' approach, for the benefit of the OP 
> (there's nothing wrong with your solution, this is just for educational 
> purposes):
> import Numeric as N
> a=N.zeros((52,52))
> for line in open('data'):
>     m,n=map(int,line.split())
>     a[m,n] += 1
> Less temporaries, these days files are their own iterators ...

... or more au courant:

     for line in file('data')

-- per the Python library docs:

"file() is new in Python 2.2. The older built-in open() is an alias
for file()."

More information about the SciPy-user mailing list