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:

  1. Machine Learning
  2. 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.        ]]





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.