简体   繁体   中英

Gamma Function in Python

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

Yes, you can. In the module math there are special functions coded such as the Gamma function.

Look at here

我会使用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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM