SciPy代替GNU Octave [英] SciPy instead of GNU Octave

查看:97
本文介绍了SciPy代替GNU Octave的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For my lab experiments I write small programs to help with the data analysis. I usually just need basic calculations, means, standard deviation, arbitrary weighted function fitting and plots with errorbars and fitted function.

使用GNU Octave,我可以做到这一点.我开始阅读更多有关它的语言的信息,我开始不喜欢它的前后不一,我不得不学习另一种语言.

With GNU Octave, I can do this. I started to read more into the language of it and I start to not like its inconsistencies and that I have to learn yet another language.

因此,我正在考虑将Python与SciPy和NumPy一起使用一段时间.我可以使用Python轻松地完成这些事情吗?还是让通用语言Python来完成我打算做的事情会增加开销?

So I am thinking about using Python, which I am using for a while now, with SciPy and NumPy. Can I do those things with Python easily or is it more overhead to get the general purpose language Python to do what I intend to do?

推荐答案

是的,Python生态系统使其成为日常数据分析任务的可行平台,尤其是使用IPython接口(但在此我将坚持使用标准接口). )恕我直言,"[无需学习另一种语言"是一个很强的论据,也是我倾向于将Python用于此类内容的原因之一.

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)

均值,标准差"

>>> 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])

带有错误栏和合适功能的图表"

"plots with error bars and fitted function"

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")

这篇关于SciPy代替GNU Octave的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆