Re: [Tutor] filling 2d array with zeros

2010-09-28 Thread Alex Hall
On 9/28/10, Dave Angel wrote: > > > On 2:59 PM, Alex Hall wrote: >> On 9/28/10, Steven D'Aprano wrote: >>> >>> >>> PyPy is a version of Python written in Python. It has an incredible >>> mission: to eventually produce versions of Python which are faster than >>> pure C, despite being written in

Re: [Tutor] filling 2d array with zeros

2010-09-28 Thread Dave Angel
On 2:59 PM, Alex Hall wrote: On 9/28/10, Steven D'Aprano wrote: PyPy is a version of Python written in Python. It has an incredible mission: to eventually produce versions of Python which are faster than pure C, despite being written in Python itself. Although they have a long, long way to

Re: [Tutor] filling 2d array with zeros

2010-09-28 Thread Alex Hall
On 9/28/10, Steven D'Aprano wrote: > On Tue, 28 Sep 2010 11:56:33 am Alex Hall wrote: >> > (But don't forget that Python is not necessarily written in C. >> > There's Jython, written in Java, and CLPython written in Lisp, and >> > many others. How they implement objects may be different. What >> >

Re: [Tutor] filling 2d array with zeros

2010-09-28 Thread Steven D'Aprano
On Tue, 28 Sep 2010 11:56:33 am Alex Hall wrote: > > (But don't forget that Python is not necessarily written in C. > > There's Jython, written in Java, and CLPython written in Lisp, and > > many others. How they implement objects may be different. What > > happens under the hood isn't important, s

Re: [Tutor] filling 2d array with zeros

2010-09-27 Thread Alex Hall
On 9/27/10, Steven D'Aprano wrote: > On Tue, 28 Sep 2010 06:00:41 am Alex Hall wrote: >> > [ [0]*3 ]*4 behaves the same way. There's no problem in the inner >> > list, but the outer list doesn't make four copies of [0,0,0], it >> > has *one* list repeated four times. Modify one, modify them all. >

Re: [Tutor] filling 2d array with zeros

2010-09-27 Thread Steven D'Aprano
On Tue, 28 Sep 2010 06:00:41 am Alex Hall wrote: > > [ [0]*3 ]*4 behaves the same way. There's no problem in the inner > > list, but the outer list doesn't make four copies of [0,0,0], it > > has *one* list repeated four times. Modify one, modify them all. > > That makes sense. Basically, the * ope

Re: [Tutor] filling 2d array with zeros

2010-09-27 Thread Alex Hall
On 9/27/10, Sander Sweers wrote: > On 27 September 2010 23:15, Sander Sweers wrote: >>> objects: copying the memory location, not making a deep copy and >>> getting a duplicate object. >> >> It does not copy the object it makes multiple _references_ to the *same* >> object. > > Oops, You already

Re: [Tutor] filling 2d array with zeros

2010-09-27 Thread Sander Sweers
On 27 September 2010 23:15, Sander Sweers wrote: >> objects: copying the memory location, not making a deep copy and >> getting a duplicate object. > > It does not copy the object it makes multiple _references_ to the *same* > object. Oops, You already got the idea and I should have read better.

Re: [Tutor] filling 2d array with zeros

2010-09-27 Thread Sander Sweers
On 27 September 2010 22:00, Alex Hall wrote: > That makes sense. Basically, the * operator in this case acts as a > copying command. For simple data types this is fine, but throw in a > complex type, in this case a list (though I expect that any object > would do this) and you are just doing what

Re: [Tutor] filling 2d array with zeros

2010-09-27 Thread Alex Hall
On 9/27/10, Steven D'Aprano wrote: > On Tue, 28 Sep 2010 03:54:55 am Alex Hall wrote: >> Hi again everyone, >> I have a 2d array (I guess it is technically a list) which I want to >> fill with zeros. Later I will change some values, but any I do not >> change have to be zeros. I have two complex f

Re: [Tutor] filling 2d array with zeros

2010-09-27 Thread Knacktus
Am 27.09.2010 20:29, schrieb Steven D'Aprano: On Tue, 28 Sep 2010 03:54:55 am Alex Hall wrote: Hi again everyone, I have a 2d array (I guess it is technically a list) which I want to fill with zeros. Later I will change some values, but any I do not change have to be zeros. I have two complex fo

Re: [Tutor] filling 2d array with zeros

2010-09-27 Thread Emile van Sebille
On 9/27/2010 10:54 AM Alex Hall said... What is wrong with the following line? self.am=[[(a,b) for a in range(len(self.lines)) a=0] for b in range(len(self.lines)) b=0] The a=0 and b=0 -- what do you think they're doing? Emile ___ Tutor maill

Re: [Tutor] filling 2d array with zeros

2010-09-27 Thread Steven D'Aprano
On Tue, 28 Sep 2010 03:54:55 am Alex Hall wrote: > Hi again everyone, > I have a 2d array (I guess it is technically a list) which I want to > fill with zeros. Later I will change some values, but any I do not > change have to be zeros. I have two complex for loops, but I tried to > scale things do

Re: [Tutor] filling 2d array with zeros

2010-09-27 Thread Joel Goldstick
On Mon, Sep 27, 2010 at 1:54 PM, Alex Hall wrote: > Hi again everyone, > I have a 2d array (I guess it is technically a list) which I want to > fill with zeros. Later I will change some values, but any I do not > change have to be zeros. I have two complex for loops, but I tried to > scale things

[Tutor] filling 2d array with zeros

2010-09-27 Thread Alex Hall
Hi again everyone, I have a 2d array (I guess it is technically a list) which I want to fill with zeros. Later I will change some values, but any I do not change have to be zeros. I have two complex for loops, but I tried to scale things down to a couple list comprehensions and I broke things. What