On Fri, 4 Feb 2005, alieks lao wrote:
> Once again i have a question concerning something from the tutorial im
> being tortured by.
>> ___
> x.y= \ x (dot)y(dot)
> /__ i
> i
>> How would i express this in python.
> If the above doesn't make any sense to ya'll.
> It's at the bottom of this page>>>
>http://www.pentangle.net/python/handbook/node33.html
[Note to author Michael Williams: we found a wacky typography bug on the
HTML rendering of the link above. I'm CCing you to make sure you know
about it.]
Hi Alieks,
Ah, ok, I see it: you're talking about exercise 3.10?
The guide there is using linear algebra notation: it is defining the dot
product between two vectors 'x' and 'y'. I think you're misreading the
diagram: it's more like this:
___
x dot y= \ x * y
/__ i i
i
(The period at the end of the equation is really meant to be just a
typographic period. *grin*)
As a concrete example, if we were taking the dot product between two
sequences 'x' and 'y':
x = (3, 1, 4, 1, 5)
y = (2, 7, 1, 8, 2)
then we'd be calculating, in effect:
(x[0] * y[0] +
x[1] * y[1] +
x[2] * y[2] +
x[3] * y[3] +
x[4] * y[4])
--> ( 3 * 2 +
1 * 7 +
4 * 1 +
1 * 8 +
5 * 2 )
--> ( 6 + 7 + 4 + 8 + 10 )
--> 35
Numeric Python comes with an dot() function built in:
http://www.pfdubois.com/numpy/html2/numpy-9.html#pgfId-36540
so if you're dealing strictly with Numeric arrays, you don't need to do
any work to 'dot' two arrays together. *grin*
... Oh, that's not good! Warning: It looks like the typography of
Exercise 3.10 in the HTML is screwed up. The problem as written in the
HTML is nonsensical. Look at the PDF instead. You'll see that the
question will make more sense in the PDF here:
http://www.pentangle.net/python/handbook.pdf
The GIF images in the HTML has some strange offset error that I don't
understand, but img22.gif and img23.gif are in the wrong places on the
HTML page. I'll CC the author to see if that can get fixed.
I notice that you're learning from the "Handbook of the Physics Computing
Course". There are other tutorials in:
http://www.python.org/moin/BeginnersGuide/NonProgrammers
that you may find more approachable if you want less math.
Good luck to you!