On Github kkhust / Python-for-scientific-computing
Created by Yuxiang Chen
“Python is the most powerful language you can still read.”
—Paul Dubois, MySQL“Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. Today dozens of Google engineers use Python, and we're looking for more people with skills in this language.”
—Peter Norvig, Googleprint "hello world"
def add(a, b): # define a function return a+b
with open('workfile', 'r') as f: # open a file line = f.read()
class Human: # define a class """Human docstring""" def walk(self): print 'walking ...'
x, y = y, x # switching variables
for a in 'string': # loop print a
“Premature optimization is the root of all evil.”
—Donald Knuth, TAOCP$ python -m cProfile -o demo.prof demo.py
Use gprof2dot to visualize the profiling
$ gprof2dot -f pstats demo.prof | dot -Tpng -o demo-prof.png
%module swig_math %{ #define SWIG_FILE_WITH_INIT int add(double *f, int dim1, double *g, int dim2, double *out, int dim3); %} %include "numpy.i" %init %{ import_array(); %} int add(double *IN_ARRAY1, int DIM1, double *IN_ARRAY1, int DIM1, double *INPLACE_ARRAY1, int DIM1);
from mpi import MPI mpi = MPI() def pow(x): return x**2 mpi.begin() x = range(10) result = mpi.parfor(pow, x) mpi.end()