[Numpy-discussion] initializing an array of lists

alan@ajackso... alan@ajackso...
Sat Nov 7 21:56:29 CST 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@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