是的,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])
「地塊與錯誤酒吧和適合f結」
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")
來源
2012-09-09 22:30:13
DSM
+1:漂亮的答案。 – tom10
非常感謝您的詳細解答!這應該讓我開始很快。我忘了問一個小問題:如何以一種理智的方式處理測量和錯誤元組。 (我問那[[]](http://stackoverflow.com/q/12351837/653152)。) –