[Numpy-discussion] initializing an array of lists

alan at ajackson.org alan at ajackson.org
Sat Nov 7 22:56:29 EST 2009


I want to build a 2D array of lists, and so I need to initialize the
array with empty lists :

myarray = array([[[],[],[]] ,[[],[],[]]])

Is there a clever way to do this? I could define the array

myarray = zeros( (xdim,ydim), dtype=object)
and then iterate through the elements initializing then to empty lists, but 
surely there is a better way.

-- 
-----------------------------------------------------------------------
| Alan K. Jackson            | To see a World in a Grain of Sand      |
| alan at ajackson.org          | And a Heaven in a Wild Flower,         |
| www.ajackson.org           | Hold Infinity in the palm of your hand |
| Houston, Texas             | And Eternity in an hour. - Blake       |
-----------------------------------------------------------------------



More information about the NumPy-Discussion mailing list