向量余弦值python
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.cos(x) is a function used for generating a matrix/vector/variable with the cosine value of b x (as cos(x)). This is an element wise operation where each element in numpy.cos(x) corresponds to the Cosine of that element in x.
Numpy是一個功能庫,可幫助構造或操縱矩陣和向量。 函數numpy.cos(x)是用于生成余弦值為bx的矩陣/向量/變量(作為cos(x) )的函數 。 這是一個元素明智的操作,其中numpy.cos(x)中的每個元素對應于x中該元素的余弦。
Syntax:
句法:
numpy.cos(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 cos(x) values (between -1 and 1) at each entry.
與輸入x尺寸相同的矩陣或向量或變量,在每個條目處具有cos(x)值(介于-1和1之間)。
Applications:
應用范圍:
Machine Learning
機器學習
Neural Network
神經網絡
Geometry
幾何
Physics Problems
物理問題
Python代碼打印向量/矩陣元素的余弦值 (Python code to print cosine value of vector/matrix elements)
# Linear Algebra Learning Sequence
# Element Wise Cosine operation
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)
print("\ncos(A) : ", np.cos(V))
print("\ncos(B) : \n", np.cos(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. ]]
cos(A) : [-0.83423998 0.81213169 0.99527249]
cos(B) :
[[-0.9899925 0.98589658 0.71091354]
[ 0.95079638 0.83422336 -0.39998531]]
翻譯自: https://www.includehelp.com/python/printing-cosine-value-of-vector-matrix-element-wise-operation.aspx
向量余弦值python