Printing Cosine value of vector/matrix (element wise operation) | Linear Algebra using Python

Linear Algebra using Python | numpy.cos() method: Here, we are going to learn how to print cosine value of vector/matrix (element wise operation) 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.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.

Syntax:

    numpy.cos(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 cos(x) values (between -1 and 1) at each entry.

Applications:

  1. Machine Learning
  2. Neural Network
  3. Geometry
  4. Physics Problems

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]]





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.