tanh python_带有Python示例的math.tanh()方法
tanh python
Python math.tanh()方法 (Python math.tanh() method)
math.tanh() method is a library method of math module, it is used to get the hyperbolic tangent of given number in radians, it accepts a number and returns hyperbolic tangent.
math.tanh()方法是數(shù)學(xué)模塊的庫(kù)方法,用于獲取以弧度為單位的給定數(shù)字的雙曲正切值,它接受一個(gè)數(shù)字并返回雙曲正切值。
Note: math.tanh() method accepts only numbers, if we provide anything else except the number, it returns error TypeError – "TypeError: a float is required".
注意: math.tanh()方法僅接受數(shù)字,如果我們提供除數(shù)字以外的任何其他內(nèi)容,它將返回錯(cuò)誤TypeError – “ TypeError:需要浮點(diǎn)數(shù)” 。
Syntax of math.tanh() method:
math.tanh()方法的語(yǔ)法:
math.tanh(x)Parameter(s): x – is the number whose hyperbolic tangent to be calculated.
參數(shù): x –是要計(jì)算其雙曲正切值的數(shù)字。
Return value: float – it returns a float value that is the hyperbolic tangent value of the number x.
返回值: float-返回一個(gè)浮點(diǎn)值,該值是數(shù)字x的雙曲正切值。
Example:
例:
Input:x = 1.5# function callprint(math.tanh(x))Output:0.9051482536448664Python代碼演示math.tanh()方法的示例 (Python code to demonstrate example of math.tanh() method)
# Python code to demonstrate example of # math.tanh() method# importing math module import math # number x = -10 print("math.tanh(",x,"): ", math.tanh(x))x = 0 print("math.tanh(",x,"): ", math.tanh(x))x = 1.5 print("math.tanh(",x,"): ", math.tanh(x))x = 5 print("math.tanh(",x,"): ", math.tanh(x))x = 15.45 print("math.tanh(",x,"): ", math.tanh(x))Output
輸出量
math.tanh( -10 ): -0.9999999958776927 math.tanh( 0 ): 0.0 math.tanh( 1.5 ): 0.9051482536448664 math.tanh( 5 ): 0.9999092042625951 math.tanh( 15.45 ): 0.999999999999924TypeError example
TypeError示例
# Python code to demonstrate example of # math.tanh() method with exception# importing math module import math # number x = "2.5" print("math.tanh(",x,"): ", math.tanh(x))Output
輸出量
Traceback (most recent call last):File "/home/main.py", line 9, in <module>print("math.tanh(",x,"): ", math.tanh(x)) TypeError: a float is required翻譯自: https://www.includehelp.com/python/math-tanh-method-with-example.aspx
tanh python
總結(jié)
以上是生活随笔為你收集整理的tanh python_带有Python示例的math.tanh()方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 为什么ConcurrentHashMap
- 下一篇: MySQL 精选 60 道面试题(含答案