Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python 3.11: What changed in math?

Python 3.11: What changed in math?

Introduces what's new in the math module in Python 3.11.

Kimikazu Kato

October 15, 2022

More Decks by Kimikazu Kato

Other Decks in Technology


  1. About our service Axross Recipe Leaning site for machine learning

    and data analysis User create contents, but high quality (created by professional data scientists) ݸਓͰ΋๏ਓͰ΋ར༻Ͱ͖·͢ʂ https://axross-recipe.com/
  2. math.exp2(): return 2 raised to the power of x. math.cbrt():

    return the cube root of x. Do we really need them? They can be computed using existing functions. 2x 3 x
  3. Performance >>> timeit.timeit("2**1.2", "import math") 0.013247291004518047 >>> timeit.timeit("math.exp2(1.2)", "import math")

    0.04908258400973864 >>> timeit.timeit("5**(1/3)","import math") 0.012019957997836173 >>> timeit.timeit("math.cbrt(5)","import math") 0.06318095800816081 Slower! (I don't know why)
  4. Mathematically is not de fi ned, but lim x→−∞ ax

    = lim x→∞ 1 ax = ∞ for 0−∞ |a| < 1, a ≠ 0 Thus this is reasonable.
  5. ax a > 0 x can be de fi ned

    for an arbitrary if a < 0 ax For , is only de fi ned if is integer x 0x = 0 if unde fi ned if unde fi ned also for but it is sometimes convenient to de fi ne x < 0 x > 0 x = 0 00 = 1 Mathematical de fi nition of power operation ax (Caution: sometimes di ff erent from computer implementation)
  6. The math.nan is already implemented in the past, but has

    not been available for all the environments (??) Before 3.11, the common way to get nan is float("nan")
  7. Conclusion • The math module is still improving! • Don't

    forget about math! Numpy is not everything!