On Sun, Nov 8, 2009 at 5:02 PM, Ravi <lists_r...@lavabit.com> 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]: [[[], [], []], [[], [], []]]
Have to be careful with that one: >> x = [[[]]*3]*2 >> x[0][0] = [9999] >> x [[[9999], [], []], [[9999], [], []]] but not with this one: >> x = [[[] for i in range(3)] for j in range(2)] >> x[0][0] = [9999] >> x [[[9999], [], []], [[], [], []]] _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion