[Numpy-discussion] initializing an array of lists

2009-11-07 Thread alan
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 t

Re: [Numpy-discussion] initializing an array of lists

2009-11-07 Thread Alan G Isaac
On 11/7/2009 10:56 PM, a...@ajackson.org wrote: > I want to build a 2D array of lists, and so I need to initialize the > array with empty lists : > > myarray = array([[[],[],[]] ,[[],[],[]]]) [[[] for i in range(3)] for j in range(2) ] fwiw, Alan Isaac __

Re: [Numpy-discussion] initializing an array of lists

2009-11-08 Thread alan
>On 11/7/2009 10:56 PM, a...@ajackson.org wrote: >> I want to build a 2D array of lists, and so I need to initialize the >> array with empty lists : >> >> myarray = array([[[],[],[]] ,[[],[],[]]]) > > >[[[] for i in range(3)] for j in range(2) ] > >fwiw, >Alan Isaac Thanks! I like that - concise

Re: [Numpy-discussion] initializing an array of lists

2009-11-08 Thread Ravi
On Saturday 07 November 2009 22:56:29 a...@ajackson.org wrote: > I want to build a 2D array of lists, and so I need to initialize the > array with empty lists : > > myarray = array([[[],[],[]] ,[[],[],[]]]) In [1]: [[[]]*3]*2 Out[1]: [[[], [], []], [[], [], []]] Hope this helps. Ravi

Re: [Numpy-discussion] initializing an array of lists

2009-11-08 Thread Keith Goodman
On Sun, Nov 8, 2009 at 5:02 PM, Ravi wrote: > On Saturday 07 November 2009 22:56:29 a...@ajackson.org wrote: >> I want to build a 2D array of lists, and so I need to initialize the >> array with empty lists : >> >> myarray = array([[[],[],[]] ,[[],[],[]]]) > > > In [1]: [[[]]*3]*2 > Out[1]: [[[],

Re: [Numpy-discussion] initializing an array of lists

2009-11-09 Thread Christopher Barker
a...@ajackson.org wrote: > myarray = zeros( (xdim,ydim), dtype=object) > and then iterate through the elements initializing then to empty lists, but > surely there is a better way. I tried this: In [3]: a = np.empty((2,3), dtype=np.object) In [5]: a[:,:] = [] but got: ValueError: shape mismat

Re: [Numpy-discussion] initializing an array of lists

2009-11-09 Thread Robert Kern
On Mon, Nov 9, 2009 at 12:00, Christopher Barker wrote: > a...@ajackson.org wrote: >> myarray = zeros( (xdim,ydim), dtype=object) >> and then iterate through the elements initializing then to empty lists, but >> surely there is a better way. > > I tried this: > > In [3]: a = np.empty((2,3), dtype=

Re: [Numpy-discussion] initializing an array of lists

2009-11-09 Thread Pauli Virtanen
Sat, 07 Nov 2009 21:56:29 -0600, alan wrote: > 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=obje