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
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
__
>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
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
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]: [[[],
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
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=
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