[Edu-sig] teaching Python
urnerk at qwest.net
Sun Nov 28 00:04:16 CET 2004
I agree with John that it's often a good idea to get to graphics quickly.
My approach has been to use the POV-Ray engine to consume scene description
language generated from Python. The output is ray tracings.
The latest 'Linux Journal' features POV-Ray on its cover I notice (just
bought it at the supermarket -- the article is about visualizing atmospheric
physics data; I should send a heads-up to my friend Rick, a professor in
I've used Python + POV-Ray to take data from sensors strapped to a
ballerina, captured in Excel, and create corresponding stick figure
animations (previous posts): http://www.4dsolutions.net/oscon2004/
In class, we used a similar to generate colorful polyhedra. If it's a short
class, I'll supply some of the code. We'll learn by eyeballing it,
dissecting it, and maybe writing some enhancements.
Regarding statistics and other math-type applications for Python, I like
using it conversationally, like one might use Mathematica. It's like a
calculator, but calculators don't do list comprehensions. The motivation to
save functions or classes comes from wanting to save retyping.
For example, when doing stats, it's common to want a list of random numbers.
It'd be useful to have a function with three parameters: min and max to
specify the range for the random integers, and a howmany.
>>> from random import randint
>>> def getrand(min, max, howmany):
return [randint(min,max) for i in range(howmany)]
>>> mylist = getrand(0,100,10)
[0, 58, 53, 47, 89, 61, 60, 87, 12, 18]
Then we could do stuff like:
>>> def mean(somelist):
return sum(somelist)/float(len(somelist)) # or use truedivision
Then on to standard deviation, divergence, and so on. Very short programs.
Lots of command line exploration. Then save the short programs in a module
for reuse later.
I take the same approach to teaching group theory:
More information about the Edu-sig