衍生了一个Python数组? [英] Derivative of an array in python?

查看:161
本文介绍了衍生了一个Python数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有两个numpy的数组: X 同样大小的

Currently I have two numpy arrays: x and y of the same size.

我想编写一个函数(可能是调用numpy的/ SciPy的功能......如果存在的话):

I would like to write a function (possibly calling numpy/scipy... functions if they exist):

def derivative(x, y, n = 1):
    # something
    return result

其中,结果 X 的同样大小的numpy的阵列和包含的值 N 关于向的-th衍生 X (我想要以避免不流畅的效果),使用的若干值进行评估衍生物。

where result is a numpy array of the same size of x and containing the value of the n-th derivative of y regarding to x (I would like the derivative to be evaluated using several values of y in order to avoid non-smooth results).

推荐答案

这不是一个简单的问题,但也有不少已被设计来处理它的方法。一个简单的解决方法是使用有限差分方法。命令`numpy.diff采用有限差分在这里你可以具体衍生品的顺序。维基百科也有一个页面,其中列出了需要有限差分系数获取不同精度的不同衍生物。如果numpy的功能不会做你想要的。

This is not a simple problem, but there are a lot of methods that have been devised to handle it. One simple solution is to used finite difference methods. The command `numpy.diff' uses finite differencing where you can specific the order of the derivative. Wikipedia also has a page that lists the needed finite differencing coefficients for different derivatives of different accuracies. If the numpy function doesn't do what you want.

根据您的应用程序,您还可以使用<一个href=\"http://docs.scipy.org/doc/scipy/reference/generated/scipy.fftpack.diff.html#scipy.fftpack.diff\"相对=nofollow> scipy.fftpack.diff 它采用了完全不同的技术做同样的事情。虽然你的函数需要一个定义良好的傅立叶变换。

Depending on your application you can also use scipy.fftpack.diff which uses a completely different technique to do the same thing. Though your function needs a well defined Fourier transform.

有很多很多很多的变种(如由部分有限差分运营商总和或运营商可同时支持上述两种观点在方程组的preserve称为进化常量)。你应该做的,将取决于什么问题了很大的是,你正在试图解决的问题。

There are lots and lots and lots of variants (e.g. summation by parts finite differencing operators or operators designed to preserve known evolution constants in your system of equations) on both of the two ideas above. What you should do will depend a great deal on what the problem is that you are trying to solve.

的好处是,有很多工作已经在球场上完成的。对于数值微分的维基百科页面有一些资源(虽然它的重点是有限差分技术)。

The good thing is that there a lot of work has been done on the field. The Wikipedia page for Numerical Differentiation has some resources (though it is focused on finite differencing techniques).

这篇关于衍生了一个Python数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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