Prerequisite:
先决条件:
Defining a Vector
定义向量
Defining a Matrix
定义矩阵
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)).
Numpy是一个功能库,可帮助构造或操纵矩阵和向量。 函数numpy.tanh(x)是用于生成正切双曲值为b x的矩阵/向量/变量(作为tanh(x) )的函数 。
Syntax:
句法:
numpy.tanh(x)
Input parameter(s):
输入参数:
x – could be a matrix or vector or a variable.
x –可以是矩阵,向量或变量。
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.
与输入x尺寸相同的矩阵或向量或变量,每个条目处具有tanh(x)值(介于0和1之间)。
Applications:
应用范围:
Machine Learning
机器学习
Neural Network
神经网络
Python代码将向量/矩阵元素的双曲正切值 (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. ]]
翻译自: https://www.includehelp.com/python/printing-hyperbolic-tangent-value-of-vector-matrix-elements-using-numpy-tanh.aspx