SciPy instead of GNU Octave SciPy instead of GNU Octave numpy numpy

SciPy instead of GNU Octave


Yes, the Python ecosystem makes it a viable platform for everyday data analysis tasks, especially using the IPython interface (but I'll stick to the standard one here.) The "[not having] to learn yet another language" argument is a strong one, IMHO, and is one of the reasons why I tend to use Python for this stuff.

>>> import numpy as np>>> import scipy.optimize

"I usually just need basic calculations"

>>> x = np.linspace(0, 10, 50)>>> y = 3*x**2+5+2*np.sin(x)

"means, standard deviation"

>>> y.mean()106.3687338223809>>> y.std()91.395548605660522

"arbitrary weighted function fitting"

>>> def func(x, a, b, c):...     return a*x**2+b+c*np.sin(x)... >>> ynoisy = y + np.random.normal(0, 0.2, size=len(x))>>> popt, pcov = scipy.optimize.curve_fit(func, x, ynoisy)>>> poptarray([ 3.00015527,  4.99421236,  2.03380468])

"plots with error bars and fitted function"

xerr = 0.5yerr = abs(np.random.normal(0.3, 10.0))fitted_data = func(x, *popt)# using the simplified, non-object-oriented interface here# handy for quick plotsfrom pylab import *errorbar(x, ynoisy, xerr=xerr, yerr=yerr, c="green", label="actual data")plot(x, fitted_data, c="blue", label="fitted function")xlim(0, 10)ylim(0, 350)legend()xlabel("time since post")ylabel("coolness of Python")savefig("cool.png")

sample pic