proposition for syntax for initialisation of multidimensional lists

Michael Hoffman m.h.3.9.1.without.dots.at.cam.ac.uk at example.com
Wed Oct 13 00:19:59 CEST 2004


Nils Grimsmo wrote:

> i always have trouble explaining why creation of multidimensional lists 
> is not as straight forward as it could be in python.

Maybe because that is not really a sensible thing to do with the list 
data structure, which can change in length after instantiation?

>  >>> [0] * (2,3,4)
> [[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 0, 0], [0, 0, 0, 
> 0], [0, 0, 0, 0]]]
 >
 > [SNIP]
> 
> what do you think?

I think I will continue doing this:

 >>> import numarray
 >>> numarray.zeros((2,3,4))
array([[[0, 0, 0, 0],
         [0, 0, 0, 0],
         [0, 0, 0, 0]],

        [[0, 0, 0, 0],
         [0, 0, 0, 0],
         [0, 0, 0, 0]]])
-- 
Michael Hoffman



More information about the Python-list mailing list