NumPy - cos() function
The NumPy cos() function is used to calculate trigonometric cosine of given angle in radians.
Syntax
numpy.cos(x, out=None)
Parameters
x |
Required. Specify array (array_like) containing elements as angles in radians of which the trigonometric cosine is calculated. |
out |
Optional. Specify a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. |
Return Value
Returns the cosine of each element of x.
Example:
In the example below, numpy cos() function is used to calculate the cosine of each element present in array Arr.
import numpy as np Arr = np.array([0, 30, 60, 90]) #converting the angles in radians Arr = Arr*np.pi/180 print("The cos value of angles:") print(np.cos(Arr))
The output of the above code will be:
The cos value of angles: [ 1.00000000e+00 8.66025404e-01 5.00000000e-01 6.12323400e-17]
❮ NumPy - Functions