this script demonstrates the implementation of the tangent hyperbolic or tanh function the function takes a vector of k real numbers as input and then ex exex ex after through tanh the element of the vector mostly 1 between 1 script inspired from its corresponding wikipedia article https en wikipedia orgwikiactivationfunction implements the tanh function parameters vector np ndarray returns tanh np array the input numpy array after applying tanh mathematically ex exex ex can be written as 21e2x1 examples tangenthyperbolicnp array1 5 6 0 67 array 0 76159416 0 9999092 0 99998771 0 58497988 tangenthyperbolicnp array8 10 2 0 98 13 array 0 99999977 1 0 96402758 0 7530659 1 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 tangent_hyperbolic np array 1 5 6 0 67 array 0 76159416 0 9999092 0 99998771 0 58497988 tangent_hyperbolic np array 8 10 2 0 98 13 array 0 99999977 1 0 96402758 0 7530659 1
import numpy as np


def tangent_hyperbolic(vector: np.ndarray) -> np.ndarray:
    

    return (2 / (1 + np.exp(-2 * vector))) - 1


if __name__ == "__main__":
    import doctest

    doctest.testmod()