数値計算

abs

abs(x)

xの絶対値を返す。

a = abs(-3.5)  # -3.5の絶対値(3.5)をaに代入

atan

atan(x)

x の逆正接を、ラジアンで返す。

a = atan(1)  # aに0.7853981633974483(π/4)を代入

cos

cos(x)

角度x(ラジアン)の余弦を返す。

a = cos(0)  # aに1を代入

cosh

cosh(x)

xの逆双曲線余弦を返す。

a = cosh(0)  # aに1を代入

degrees

degrees(x)

角度xをラジアンから度に変換する。

a = degrees(0.7853981633974483)  # aに45.0を代入

exp

exp(x)

自然対数の低eのx上を返す。

a = exp(1)  # aに2.71828182846(e)を代入

log

log(x[, base])

引数が1つの場合、xの自然対数を返す。

引数が2つの場合、2つ目の引数baseを低としたxの対数を返す。

a = log(2.71828182846)  # aに1.000000000を代入
a = log(100,10) #aに2を代入

normalvariate

normalvariate(mu, sigma)

正規分布に従う乱数を返す。

  • mu - 正規分布の平均。

  • sigma - 正規分布の標準偏差。

a = normalvariate(0,1)  # aに標準正規分布に従う乱数を代入

pi

pi()

円周率πの値を返す。

a = pi()  # aに3.141592653589793を代入

radians

radians(x)

角度xを度からラジアンに変換する。

a = radians(45)  # aに0.7853981633974483を代入

rand

rand()

0.0以上1.0未満の一様乱数値(ランダムな値)を返す。

a = rand()  # aに0.0~1.0のランダムな値を代入

randint

randint(a, b)

a以上b以下であるようなランダムな整数を返す。

a = randint(4,9)  # aに4~9の整数いずれかを代入

randuniform

randuniform(a, b)

a以上b以下(a>bであればb以上a以下)の一様乱数値を返す。

a = randuniform(3,5)  # aに3以上5以下のランダムな値を代入

round

round(x[, ndigits])

実数xの値を四捨五入した整数を返す。
2つ目の引数ndigitsが与えられた場合は、小数部をndigits桁に丸めた値を返す。

a = round(3.5)  # aに4を代入
a = round(3.14,1) # aに3.1を代入

sin

sin(x)

角度x(ラジアン)の正弦を返す。

a = sin(0)  # aに0を代入

sinh

sinh(x)

xの双曲線正弦を返す。

a = sinh(0)  # aに0を代入

sqrt

sqrt(x)

xの平方根を返す。

a = sqrt(2)  # aに1.4142135623730951を代入

tan

tan(x)

角度x(ラジアン)の正接を返す。

a = tan(0)  # aに0を代入

tanh

tanh(x)

x の双曲線正接を返す。

a = tanh(0)  # aに0を代入