本文共 1344 字,大约阅读时间需要 4 分钟。
python独立log示例
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 code to demonstrate example of # math.log1p() method# importing math moduleimport math# log1p()x = 21print("Natural logarithm of 1 +", x, " is = ", math.log1p(x))x = 10.23print("Natural logarithm of 1 +", x, " is = ", math.log1p(x))
Output
输出量
Natural logarithm of 1 + 21 is = 3.091042453358316Natural logarithm of 1 + 10.23 is = 2.418588768750352
翻译自:
python独立log示例
转载地址:http://guxzd.baihongyu.com/