Re: How to make arrays from Lists

2008-11-16 Thread Michiel Overtoom
[EMAIL PROTECTED] wrote: x = [[0] * ncols for i in nrows] That gives an error... small typo corrected: y = [[0] * ncols for i in range(nrows)] Greetings, -- "The ability of the OSS process to collect and harness the collective IQ of thousands of individuals across the Internet is simply ama

Re: How to make arrays from Lists

2008-11-14 Thread Gabriel Genellina
En Tue, 11 Nov 2008 23:09:25 -0200, <[EMAIL PROTECTED]> escribió: On Nov 11, 7:48 pm, [EMAIL PROTECTED] wrote: To create a 2D list, that is a list of lists: x = [[0] * ncols for i in nrows] Many thanks, I don't think I would ever 'discovered' this. Try reading the FAQ: http://www.python.

Re: How to make arrays from Lists

2008-11-11 Thread Robert Kern
[EMAIL PROTECTED] wrote: On Nov 11, 7:48 pm, [EMAIL PROTECTED] wrote: gc_ott: How do I change the value of any element to produce (say) [[99,0,0],[0,0,0],[0,0,0]] ? gordc To create a 2D list, that is a list of lists: x = [[0] * ncols for i in nrows] (Don't do what you were doing, because you

Re: How to make arrays from Lists

2008-11-11 Thread gc_ottawa
On Nov 11, 7:48 pm, [EMAIL PROTECTED] wrote: > gc_ott: > > > How do I change the value of any element to produce (say) > > [[99,0,0],[0,0,0],[0,0,0]] ? > > > gordc > > To create a 2D list, that is a list of lists: > x = [[0] * ncols for i in nrows] > (Don't do what you were doing, because you end w

Re: How to make arrays from Lists

2008-11-11 Thread bearophileHUGS
gc_ott: > How do I change the value of any element to produce (say) > [[99,0,0],[0,0,0],[0,0,0]] ? > > gordc To create a 2D list, that is a list of lists: x = [[0] * ncols for i in nrows] (Don't do what you were doing, because you end with many references to the same list, and that will give you t

Re: How to make arrays from Lists

2008-11-11 Thread Benjamin Kaplan
On Tue, Nov 11, 2008 at 7:32 PM, <[EMAIL PROTECTED]> wrote: > I want to construct a 2-dimensional array from a List but I cannot > find a simple way of changing any element. For example, construct a > 3x3 array like this:- > >>> x=[0,0,0] > x=[x]*3 > this produces [[0,0,0],[0,0,0],[0,0,0]. S

How to make arrays from Lists

2008-11-11 Thread gc_ottawa
I want to construct a 2-dimensional array from a List but I cannot find a simple way of changing any element. For example, construct a 3x3 array like this:- >>> x=[0,0,0] x=[x]*3 this produces [[0,0,0],[0,0,0],[0,0,0]. So far so good. How do I change the value of any element to produce (say)