まぬねこの足跡。。。

備忘録+たのしさ+ひっそりと

2023-06-22から1日間の記事一覧

Python - math.ulp(x):浮動小数点数 x の最下位ビットの値

概要 インポート 実行結果 表示イメージ 概要ulp(x) 浮動小数点数 x の最下位ビットの値 x=0:最小の正の非正規化浮動小数点数を返す。 mathモジュール インポート import math 実行結果 import math print(math.ulp(1)) print(math.ulp(0)) 表示イメージ 2.…

Python - math.trunc(x):小数部切捨て

概要 インポート 実行結果 表示イメージ 概要trunc(x) 小数部切捨て mathモジュール インポート import math 実行結果 import math print(math.trunc(2)) print(math.trunc(5.4321)) 表示イメージ 2 5

Python - math.remainder(x,y):x÷yの剰余

概要 インポート 実行結果 表示イメージ 概要remainder(x,y) x÷yの剰余 IEEE 754 標準方式。 通常・・・厳密な商に近い整数が解になる 7÷3=2.33...→整数2と3なら2が商に近い→剰余7-3×2=1 5÷3=1.66...→整数1と2なら2が商に近い→剰余5-3×2=-1 厳密な商の下一桁が5…

Python - math.prod(iterable, *, start=1):総積

概要 インポート 実行結果 表示イメージ 概要prod(iterable, *, start=1) 総積 mathモジュール インポート import math 実行結果 import math print(math.prod([1,2,3])) print(math.prod([0,1,2,3])) print(math.prod([1.1,2.2,3.3])) print(math.prod([0.0…

Python - math.perm(n, k=None):順列(重複無し)

概要 インポート 実行結果 表示イメージ 概要perm(n, k=None) k:省略、Noneのとき、 順列(重複無し) mathモジュール インポート import math 実行結果 import math print(math.perm(5)) print(math.perm(5,None)) print(math.perm(5,3)) 表示イメージ 120 1…

Python - math.nextafter(x,y):xからyにより近いfloat値

概要 インポート 実行結果 表示イメージ 概要nextafter(x, y) xからyに向かって近いfloatの値 mathモジュール インポート import math 実行結果 import math print(math.nextafter(0, math.inf)) print(math.nextafter(0, -math.inf)) print(math.nextafter(…

Python - math.modf(x):小数部分、整数部分の取得

概要 インポート 実行結果 表示イメージ 概要math.modf(x) (小数部分, 整数部分)のとして共に、float型で取得。 mathモジュール インポート import math 実行結果 import math print(math.modf(1.23)) print(math.modf(1.25)) 表示イメージ (0.2299999999999…

Python - math.ldexp(x,i):x * (2**i) の解

概要 インポート 実行結果 表示イメージ 概要isqrt(x, i) frexp() の逆関数 mathモジュール インポート import math 実行結果 import math print(math.ldexp(0.5, 9)) 表示イメージ 256.0

Python - math.lcm(*int):最大公倍数

概要 インポート 実行結果 表示イメージ 概要lcm(*int) 最大公倍数を返す。 mathモジュール インポート import math 実行結果 import math print(math.lcm(10, 25)) print(math.lcm(13, 26, 39)) 表示イメージ 50 78

Python - math.isqrt(n):2乗の最大整数

概要 インポート 実行結果 表示イメージ 概要isqrt(n) n(最大値)を超えない2乗の数 mathモジュール インポート import math 実行結果 import math math.isqrt(25) 表示イメージ 5

Python - math.isnan(x):nanか

概要 インポート 実行結果 表示イメージ 参考 概要isnan(x) nanか真偽値で返す。 mathモジュール インポート import math 実行結果 import math math.isnan(math.inf - math.inf) 表示イメージ True 参考Python - math.inf:無限大

Python - math.isinf(x):無限大か

概要 インポート 実行結果 表示イメージ 参考 概要isinf(x) 無限大か真偽値で返す。 mathモジュール インポート import math 実行結果 import math math.isinf(math.inf) 表示イメージ True 参考Python - math.inf:無限大

Python - math.isfinite(x):有限数か

概要 インポート 実行結果 表示イメージ 参考 概要isfinite(x) 有限数か真偽値で返す。 flot('inf')と同一。 mathモジュール インポート import math 実行結果 import math math.isfinite(math.inf) 無限大は有限数でない=Falseになる。 表示イメージ False…

Python - math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0):近似値か

概要 許容差 インポート 実行結果 表示イメージ 概要isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0) rel_tol:最大の差、相対許容差 ※デフォルト1e-09 :a,bが9桁同じ。 abt_tol:最小の差、絶対許容差 ※a,bが小さい時、有効。 aとbが近似値かを真偽値で返…

Python - math.gcd(*int):最大公約数

概要 インポート 実行結果 表示イメージ 概要gcd(*int) 最大公約数を返す。 mathモジュール インポート import math 実行結果 import math print(math.gcd(10, 25)) print(math.gcd(13, 26, 39)) 表示イメージ 5 13

Python イテラブル(iterable)・イテレータ(iterator)

イテラブル(iterable) 表示イメージ イテレータ(iterator) 表示イメージ ジェネレータ式 基本 表示イメージ イテラブル(iterable)反復して取得する構造 for in文で取得できる イテラブル(反復取得)可能 データ型 何度も反復取得可能:list、tuple、dict 何度…

Python - math.fsum(iterable):浮動小数の総和

概要 インポート 実行結果 表示イメージ 概要fsum(iterable) iterable内の値の正確な総和をfloat返す。 mathモジュール インポート import math 実行結果 import math math.fsum(0.2 for x in range(5)) 表示イメージ 1.0

Python - math.frexp(x):(仮数float, 指数int)で返す。

概要 インポート 実行結果 表示イメージ 概要frexp(x) (仮数float, 指数int)で返す。 mathモジュール インポート import math 実行結果 import math math.frexp(256) 表示イメージ (0.5, 9)

Python - math.fmod(x,y):剰余・・・float 推奨

概要 インポート 実行結果 表示イメージ 概要math.fmod(x, y) の厳密な剰余を返す。符号はxと同じになる。 「%」剰余演算子は、絶対値が小さい方になる。その為、fmod()相違すると相違することあり。 浮動小数点は、fmod()、整数は、「%」剰余演算子 推奨。 mat…

Python - math.floor(x):小数点以下、切捨て

概要 インポート 実行結果 表示イメージ 概要math.floor(x) 小数点以下、切上げ int型を返す。 mathモジュール インポート import math 実行結果 import math print(math.floor(123.456789)) print(math.floor(123)) 表示イメージ 123 123

Python - math.ceil(x):x以上の最小整数値

概要 インポート 実行結果 表示イメージ 概要math.ceil(x) x以上の最小int値 mathモジュール インポート import math 実行結果 import math print(math.ceil(123.456789)) print(math.ceil(123)) 表示イメージ 124 123

Python - math.factorial(n):階乗

概要 インポート 実行結果 表示イメージ 概要math.factorial(n) n=int nの階乗を返す。 mathモジュール インポート import math 実行結果 import math print(math.factorial(5)) 表示イメージ 120

Python - math.fabs(x):絶対値

概要 インポート 実行結果 表示イメージ 概要math.fabs(x) 絶対値を返す mathモジュール インポート import math 実行結果 import math print(math.fabs(-123.45)) 表示イメージ 123.45

Python - math.copysign(x,y):値を 指定変数の符号に変換

概要 インポート 実行結果 表示イメージ 概要math.copysign(x, y) x を y の符号にし、float型で返す。 mathモジュール インポート import math 実行結果 import math print(math.copysign(1, 1)) print(math.copysign(1, -1)) print(math.copysign(-1, 1)) …

Python - math.comb(n,k):組合せ総数

概要 インポート 実行結果 表示イメージ 概要math.comb(n, k)) n個中、k個選ぶ組合せ総数 組合せ総数を返す mathモジュール インポート import math 実行結果 import math print(math.comb(7,2)) 表示イメージ 21