Home »
Python »
Linear Algebra using Python
Printing hyperbolic tangent value of vector/matrix elements using numpy.tanh() | Linear Algebra using Python
Linear Algebra using Python | numpy.tanh(): Here, we are going to learn how to print hyperbolic tangent value of vector/matrix elements using numpy.tanh() in Python?
Submitted by Anuj Singh, on May 23, 2020
Prerequisite:
Numpy is the library of function that helps to construct or manipulate matrices and vectors. The function numpy.tanh(x) is a function used for generating a matrix / vector / variable with the Tangent Hyperbolic value of b x (as tanh(x)).
Syntax:
numpy.tanh(x)
Input parameter(s):
- x – could be a matrix or vector or a variable.
Return value:
A Matrix or vector or a variable of the same dimensions as input x with tanh(x) values (between 0 and 1) at each entry.
Applications:
- Machine Learning
- Neural Network
Python code to hyperbolic tangent value of vector/matrix elements
# Linear Algebra Learning Sequence
# Printing hyperbolic tangent value of
# vector/matrix elements using numpy.tanh()
import numpy as np
#Use of np.array() to define an Vector
V = np.array([323,.623,823])
print("The Vector A : ",V)
VV = np.array([[3,63,.78],[.315,32,42]])
print("\nThe Vector B : \n",VV)
pro = V.dot(VV.T)
print("\nProduct of two vectors : ", pro)
print("\ntanh(AB) : ", np.tanh(pro))
print("\ntanh(A) : ", np.tanh(V))
print("\ntanh(B) : \n", np.tanh(VV))
Output:
The Vector A : [3.23e+02 6.23e-01 8.23e+02]
The Vector B :
[[ 3. 63. 0.78 ]
[ 0.315 32. 42. ]]
Product of two vectors : [ 1650.189 34687.681]
tanh(AB) : [1. 1.]
tanh(A) : [1. 0.55321335 1. ]
tanh(B) :
[[0.99505475 1. 0.65270671]
[0.30497892 1. 1. ]]