Python 计算函数的逆函数--库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15200560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 19:29:38  来源:igfitidea点击:

Calculate inverse of a function--Library

pythoncmath

提问by username_4567

Is there any library available to have inverse of a function? To be more specific, given a function y=f(x)and domain, is there any library which can output x=f(y)? Sadly I cannot use matlab/mathematics in my application, looking for C/Python library..

是否有任何库可用于函数的反函数?更具体地说,给定一个函数y=f(x)和域,是否有可以输出的库x=f(y)?遗憾的是,我无法在我的应用程序中使用 matlab/mathematics,寻找 C/Python 库..

回答by ev-br

As has already been mentioned, not all functions are invertible. In some cases imposing additional constraints helps: think about the inverse of sin(x).

如前所述,并非所有函数都是可逆的。在某些情况下,施加额外的约束有助于:考虑 的倒数sin(x)

Once you are sure your function has a unique inverse, solve the equation f(x) = y. The solution gives you the inverse, y(x).

一旦你确定你的函数有一个唯一的逆,解方程f(x) = y。该解决方案为您提供了相反的y(x).

In python, look for nonlinear solvers from scipy.optimize.

在 python 中,从scipy.optimize.

回答by alvarosg

I am a bit late, but for future readers of the post, I just published a python package that does this precisely. https://pypi.python.org/pypi/pynverseThere is a detailed description of how to use it and how it does it in the description!

我有点晚了,但对于这篇文章的未来读者,我刚刚发布了一个精确执行此操作的 python 包。https://pypi.python.org/pypi/pynverse在说明中有详细的使用方法和操作方法!