populating a doubly-subscripted array

Mark Wooding mdw at distorted.org.uk
Tue Nov 9 23:09:58 CET 2010

Gregory Ewing <greg.ewing at canterbury.ac.nz> writes:

> A reasonably elegant way to fix this is to use list comprehensions
> for all except the innermost list:
>    ff = [[0.0]*5 for i in xrange(5)]

Yes, this is a good approach.  I should have suggested something like
this as a solution myself, rather than merely explaining the problem.

> If you're computing heavily with arrays, you might also consider
> using numpy arrays instead of lists.

Also a good idea.

-- [mdw]

More information about the Python-list mailing list