pyspark.sql.functions.tanh#

pyspark.sql.functions.tanh(col)[source]#

Computes hyperbolic tangent of the input column.

New in version 1.4.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or column name

hyperbolic angle

Returns
Column

hyperbolic tangent of the given value as if computed by java.lang.Math.tanh()

Examples

Example 1: Compute the hyperbolic tangent sine

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([(-1,), (0,), (1,)], ["value"])
>>> df.select("*", sf.tanh(df.value)).show()
+-----+-------------------+
|value|        TANH(value)|
+-----+-------------------+
|   -1|-0.7615941559557...|
|    0|                0.0|
|    1| 0.7615941559557...|
+-----+-------------------+

Example 2: Compute the hyperbolic tangent of invalid values

>>> from pyspark.sql import functions as sf
>>> spark.sql(
...     "SELECT * FROM VALUES (FLOAT('NAN')), (NULL) AS TAB(value)"
... ).select("*", sf.tanh("value")).show()
+-----+-----------+
|value|TANH(value)|
+-----+-----------+
|  NaN|        NaN|
| NULL|       NULL|
+-----+-----------+