MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / tangent_hyperbolic

Function tangent_hyperbolic

maths/tanh.py:16–37  ·  view source on GitHub ↗

Implements the tanh function Parameters: vector: np.ndarray Returns: tanh (np.array): The input numpy array after applying tanh. mathematically (e^x - e^(-x))/(e^x + e^(-x)) can be written as (2/(1+e^(-2x))-1 Examples: >>> tang

(vector: np.ndarray)

Source from the content-addressed store, hash-verified

14
15
16def tangent_hyperbolic(vector: np.ndarray) -> np.ndarray:
17 """
18 Implements the tanh function
19
20 Parameters:
21 vector: np.ndarray
22
23 Returns:
24 tanh (np.array): The input numpy array after applying tanh.
25
26 mathematically (e^x - e^(-x))/(e^x + e^(-x)) can be written as (2/(1+e^(-2x))-1
27
28 Examples:
29 >>> tangent_hyperbolic(np.array([1,5,6,-0.67]))
30 array([ 0.76159416, 0.9999092 , 0.99998771, -0.58497988])
31
32 >>> tangent_hyperbolic(np.array([8,10,2,-0.98,13]))
33 array([ 0.99999977, 1. , 0.96402758, -0.7530659 , 1. ])
34
35 """
36
37 return (2 / (1 + np.exp(-2 * vector))) - 1
38
39
40if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected