Compact syntax for 0-matrix?

Kirby Urner urner at alumni.princeton.edu
Mon May 29 01:15:23 EDT 2000


Alex <cut_me_out at hotmail.com> wrote:

>
>How about this:
>
>from copy import copy
>
>def zeromatrix (n, m):
>    line = n * [0]
>    matrix = map (copy, m * [line])
>    return matrix

I like it.

>I agree with the guy who said you should check out Numeric Python,
>though.  It will probably work out to be more flexible for you, in the
>long run.
>
>Alex.

I've used Numeric Python some.  However, in a teaching
context, I don't want to hide anything from view.
NumPy doesn't always meet my criteria in this regard,
even though it is fast and useful.  I'm not doing 
really big matrices, and speed isn't really important.

But good advice in any case, and I appreciate it. 
Plus I like your function.  Teaches me something.

Kirby




More information about the Python-list mailing list