Computer tools > python

python

Summary

Hello_World.py

#!/bin/python
print('Hello World\n') # comment

fit_python.py

#!/usr/bin/python
from scipy import optimize
from numpy import array

x = [0.0, 1.0, 2.0]
y = [1.0, 0.5, 0.0]
# use the lambda shortcut or define standard functions with def fit():
fit = lambda p, x: p[0] + p[1]*x + p[2]*x**2
err = lambda p, x, y: fit(p,x) - y
p0 = [1.0,1.0,1.0]
# calls optimize.leastsq to find optimal parameters, converts lists into numpy.array on the fly
p, success = optimize.leastsq(err, p0, args=(array(x), array(y)), ftol=5e-9, xtol=5e-9)
print p
Suggested way: wrap python script into a bash script. Example:
fit_python