Re: Using '__mul__' within a class
- From: Piet van Oostrum <piet@xxxxxxxx>
- Date: Sat, 24 Sep 2005 23:14:16 +0200
>>>>> James Stroud <jstroud@xxxxxxxxxxxx> (JS) wrote:
>JS> def Multiply(self, other):
>JS> self.a = self.a * other.a + self.b * other.b
>JS> self.b = self.a * other.b + self.b * other.c
>JS> self.c = self.b * other.b + self.c * other.c
I gues this will give the wrong result because the calculation of self.b is
supposed to use the original value of self.a, not the newly calculated one.
Similar for self.c. The following should do that:
self.a, self.b, self.c = (self.a * other.a + self.b * other.b,
self.a * other.b + self.b * other.c,
self.b * other.b + self.c * other.c)
--
Piet van Oostrum <piet@xxxxxxxx>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet@xxxxxxxxxxxxxx
.
- References:
- Using '__mul__' within a class
- From: Gerard Flanagan
- Re: Using '__mul__' within a class
- From: James Stroud
- Using '__mul__' within a class
- Prev by Date: Re: Poor man's OCR: need performance improvement tips
- Next by Date: Re: Using '__mul__' within a class
- Previous by thread: Re: Using '__mul__' within a class
- Next by thread: Re: Using '__mul__' within a class
- Index(es):
Relevant Pages
|