是的,Python 生态系统使其成为日常数据分析任务的可行平台,尤其是使用 IPython 接口(但我将在这里坚持使用标准接口。)“[不必] 学习另一种语言”的论点恕我直言,它很强大,这也是我倾向于使用 Python 来处理这些东西的原因之一。
>>> import numpy as np
>>> import scipy.optimize
“我通常只需要基本的计算”
>>> x = np.linspace(0, 10, 50)
>>> y = 3*x**2+5+2*np.sin(x)
“均值,标准差”
>>> y.mean()
106.3687338223809
>>> y.std()
91.395548605660522
“任意加权函数拟合”
>>> 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)
>>> popt
array([ 3.00015527, 4.99421236, 2.03380468])
“带有误差线和拟合函数的图”
xerr = 0.5
yerr = abs(np.random.normal(0.3, 10.0))
fitted_data = func(x, *popt)
# using the simplified, non-object-oriented interface here
# handy for quick plots
from 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")