python獨立log示例
Python math.log1p()方法 (Python math.log1p() method)
math.log1p() method is a library method of math module, it is used to get the natural logarithm of 1+x (base e), it accepts a number and returns the natural logarithm of 1+number on base e.
math.log1p()方法是數學模塊的庫方法,用于獲取1 + x(以e為底)的自然對數,它接受一個數字并以e為基礎返回1+數字的自然對數。
Note: If we provide anything else except a number, the method returns a TypeError – "TypeError: a float is required".
注意:如果我們提供除數字以外的任何其他內容,該方法將返回TypeError – “ TypeError:需要浮點數” 。
Syntax of math.log1p() method:
math.log1p()方法的語法:
math.log1p(x)
Parameter(s):x – is the number whose logarithm to be calculated.
參數: x –是要計算其對數的數字。
Return value: float – it returns a float value that is the natural logarithm of 1 + x.
返回值: float-返回一個浮點值,它是1 + x的自然對數。
Example:
例:
Input:
x = 21
# function call
print(math.log1p(x))
Output:
3.091042453358316
Python代碼演示math.log1p()方法的示例 (Python code to demonstrate example of math.log1p() method)
# python code to demonstrate example of
# math.log1p() method
# importing math module
import math
# log1p()
x = 21
print("Natural logarithm of 1 +", x, " is = ", math.log1p(x))
x = 10.23
print("Natural logarithm of 1 +", x, " is = ", math.log1p(x))
Output
輸出量
Natural logarithm of 1 + 21 is = 3.091042453358316
Natural logarithm of 1 + 10.23 is = 2.418588768750352
翻譯自: https://www.includehelp.com/python/math-log1p-method-with-example.aspx
python獨立log示例