Python math.gamma() メソッド
Python math.gamma(x)メソッドは x におけるガンマ関数(Gamma 関数)を返します。
ガンマ関数は、オイラーの第二積分とも呼ばれ、階乗関数を実数と複素数に拡張した関数の一種です。
数値の対数ガンマ値を求めるには、次のmath.lgamma()メソッドを使用してください。
Python バージョン: 3.2
構文
math.gamma() メソッドの構文は次のとおりです。
math.gamma(x)
パラメータの説明:
- x-- 必須、数値。数値が負の整数の場合は ValueError を返します。数値でない場合は TypeError を返します。
戻り値
x におけるガンマ関数を表す浮動小数点数。
例
次の例では、さまざまな数値のガンマ関数を計算します:
例
# math モジュールをインポート
import math
# さまざまな数値のガンマ関数を計算
print(math.gamma(-0.1))
print(math.gamma(8))
print(math.gamma(1.2))
print(math.gamma(80))
print(math.gamma(-0.55))
import math
# さまざまな数値のガンマ関数を計算
print(math.gamma(-0.1))
print(math.gamma(8))
print(math.gamma(1.2))
print(math.gamma(80))
print(math.gamma(-0.55))
出力結果:
-10.686287021193193 5040.0 0.9181687423997604 8.946182130782976e+116 -3.578429819277059その他の拡張
Python math モジュール