I'm fairly new to Python but would like to use Euler's Gamma Function in a function I am writing. I'd prefer not to write it as an integral and was wondering if there's something I can import that easily defines the gamma function.
Thanks
I'm fairly new to Python but would like to use Euler's Gamma Function in a function I am writing. I'd prefer not to write it as an integral and was wondering if there's something I can import that easily defines the gamma function.
Thanks
I'd use scipy.special.gamma()
.
There is another way:
from mpmath import gamma
print(float(gamma(0.5)))
1.772453850905516
If you want to go deep with Python and other methods I'll recommend that you look at numpy and scipy libraries.
A gamma function can be as easy as
from scipy.stats import gamma
a = 1.99323054838
rv = gamma(a)
That's it, check https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.stats.gamma.html#scipy.stats.gamma for more info and https://www.scipy.org/ if you want to know more about scientific computing with python.