SciPy而不是GNU Octave

Mar*_*ing 13 python numpy octave scipy

对于我的实验室实验,我编写了小程序来帮助进行数据分析.我通常只需要基本的计算,平均值,标准偏差,任意加权函数拟合以及带有误差和拟合函数的图.

使用GNU Octave,我可以做到这一点.我开始更多地阅读它的语言,我开始不喜欢它的不一致性,我不得不学习另一种语言.

所以我正在考虑使用Python,我现在使用的是SciPy和NumPy.我可以轻松地使用Python做这些事情,还是让通用语言Python做我打算做的事情的开销更大?

DSM*_*DSM 20

是的,Python生态系统使它成为日常数据分析任务的可行平台,特别是使用IPython接口(但我会坚持使用标准的接口)."[没有学习另一种语言"的论点是强大的一,恕我直言,这也是我倾向于使用Python来解决这个问题的原因之一.

>>> import numpy as np
>>> import scipy.optimize
Run Code Online (Sandbox Code Playgroud)

"我通常只需要基本的计算"

>>> x = np.linspace(0, 10, 50)
>>> y = 3*x**2+5+2*np.sin(x)
Run Code Online (Sandbox Code Playgroud)

"手段,标准偏差"

>>> y.mean()
106.3687338223809
>>> y.std()
91.395548605660522
Run Code Online (Sandbox Code Playgroud)

"任意加权函数拟合"

>>> 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])
Run Code Online (Sandbox Code Playgroud)

"带有误差条和拟合函数的图"

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")
Run Code Online (Sandbox Code Playgroud)

样本图片