开发者

Function arithmetic library for python

开发者 https://www.devze.com 2023-01-28 01:14 出处:网络
I\'m searching for a library that will let me manipulate functions w开发者_StackOverflowith the standard operators (*, -, *, /, etc.).

I'm searching for a library that will let me manipulate functions w开发者_StackOverflowith the standard operators (*, -, *, /, etc.).

Lets suppose you have a function f(x) = x ** 2 and g(x) = x + 2. I'd like to be able to write f * g and get a new functor that is essentialy x ** 2 * (x + 2) or f(g) and get (x + 2) ** 2.

I know this is not too hard to implement, you'll just have to make a Functor class and overload it's __call__ function, but I'm hoping there is a 3rd party library for it.

I'm not trying to use this for anything heavyweight just for learning. Thanks for the help.


Sympy should do what you want.


I don't completely understand what you're after, but does the operator module (in the standard library) help at all? It defines functions for all the standard arithmetic operators.

0

精彩评论

暂无评论...
验证码 换一张
取 消