Skip to main content

tanh

Computes hyperbolic tangent of the input column. Supports Spark Connect.

For the corresponding Databricks SQL function, see tanh function.

Syntax

Python
from pyspark.databricks.sql import functions as dbf

dbf.tanh(col=<col>)

Parameters

Parameter

Type

Description

col

pyspark.sql.Column or column name

hyperbolic angle

Returns

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

Examples

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

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