【问题标题】:SciPy instead of GNU OctaveSciPy 而不是 GNU Octave
【发布时间】:2012-09-02 19:44:50
【问题描述】:

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

使用 GNU Octave,我可以做到这一点。我开始更多地阅读它的语言,我开始不喜欢它的不一致之处,并且我必须学习另一种语言。

所以我正在考虑将 Python 与 SciPy 和 NumPy 一起使用,我现在使用了一段时间。我可以用 Python 轻松地做这些事情,还是让通用语言 Python 做我打算做的事情的开销更大?

【问题讨论】:

    标签: python numpy scipy octave


    【解决方案1】:

    是的,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")
    

    【讨论】:

    • 非常感谢您的详细回答!这应该让我很快开始。我只有一件小事忘了问:如何以理智的方式处理测量和错误元组。 (我问过there。)
    猜你喜欢
    • 2015-11-29
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多