Question about scientific calculations in Python
Martin Kaufmann
martinkaufmann at yahoo.com
Wed Mar 13 07:06:46 EST 2002
On Tue, 12 Mar 2002 23:04:19 -0600, "Jason Orendorff"
<jason at jorendorff.com> wrote:
Thanks a lot! This is really an amazingly helpful reply. This group is
a good example for how Usenet should ideally be!
>I'm going to attempt to explain how you can do this with Numeric
>Python, but you'll have to understand I have no clue what I'm
>doing scientifically.
It doesn't matter. You got the point of my program.
>So in particular I'm assuming that "atoms" is a scalar, say atoms=1000.
>I also don't really know why you're using s_vector[1:] ... intentionally
>omitting the zeroth data point for some reason...?
This is just because the program that calculates the scattering
factors (which I didn't write myself) starts too low for our
purpose...
>Anyway, here's an interactive session that implements the above
>algorithm using Numeric, with *no loops*. Or rather, the loops are all
>hidden away where you don't have to worry about them. (They should
>run faster, too.)
[NumPy Tutorial for Dummies snipped...]
Thanks! I can't claim that I understood every line, but with this code
and the NumPy documentation I will make a huge step forward.
>The histogram version is up to you. :)
As an exercise for the reader...
>Numeric lets you mix arrays and scalars randomly and it happily
>distributes multiplication and so forth. So the resulting code
>looks a bit more like the original formulas. Some folks like that.
>But if you don't, you can always code this in C and it'll be faster
>still. It won't take very long to learn C. The real problem is
>that C programs can be very difficult and time-consuming to debug.
If I write anything at all in C, it will only be a small part. Python
is so much more fun!
Many Thanks,
Martin
More information about the Python-list
mailing list