prev | Draft Version 534 (Thu Dec 1 09:18:44 2005) | next |
http://www.users.cloud9.net/~bradmcc/APL.html
for the scary detailsNumeric
module (sometimes referred to as NumPy)
matplotlib
for MATLAB-style plottingnumarray
moduleSciPy
Python Imaging Library
is a toolkit for working with images in just about every format you'll ever encounterimport sys, Image # Color bands in image. RED, GREEN, BLUE = 0, 1, 2 # Read image. im = Image.open(sys.argv[1]) # Split the image into individual bands. source = im.split() # Create a bitmask of regions where there's red. def lessThan100(x): if x > 128: return x else: return 0 mask = source[RED].point(lessThan100) # Process the green band. def reduceByHalf(x): return x * 0.75 out = source[GREEN].point(reduceByHalf) # Paste the processed band back, but only where red was < 100. source[GREEN].paste(out, None, mask) # Build a new multiband image. im = Image.merge(im.mode, source) # Save for display. im.save(sys.argv[2])
GIMP
SCons
combines the most useful features of Make with the full power of Python# What does the program depend on? dependencies = ['file1.c', 'file2.c'] if os.platform == 'win32': dependencies.append('win32.c') # Which version are we building? if 'debug' in COMMAND_LINE_TARGETS: Program('hello_dbg', dependencies) else: Program('hello', dependencies)
PyObject
that contains:
self
is NULL
for pure functions, and an object for methodsargs
is a variable-length list of argumentsPyArg_ParseTuple
to extract arguments' values/* Triple an integer value. */ static PyObject * triple(PyObject * self, PyObject * args) { int val; if (!PyArg_ParseTuple(args, "i", &val)) { return NULL; } val = val * 3; return Py_BuildValue("i", val); }
NULL
to signal errorPy_BuildValue
to build a Python structure with the result value/* Table of module contents (handed back to Python at initialization). */ static PyMethodDef contents[] = { {"triple", triple, METH_VARARGS}, {NULL, NULL} }; /* Initialization function. */ void inittriple() { Py_InitModule("triple", contents); }
contents
has one entry for each functioninitXYZ
for the module XYZ
Py_InitModule
to pass the table of module contents to the interpreter.dll
on Windows, .so
on Unix)import triple
and call triple.triple(11)
param1
and param2
Introduce Parameter Object
to combine co-occurring parameters into one valueInternet Groupware for Scientific Collaboration
talks about how much more the web could do for scientistsprev | Copyright © 2005, Python Software Foundation. See License for details. | next |