What is the numpy.cos() function in Numpy?
Overview
The numpy.cos() function in NumPy returns an array’s cosine element-wise.
Syntax
numpy.cos(x)
Parameter value
The numpy.cos() function takes the parameter value x which represents the input array in radians.
Return value
The numpy.cos() function returns the corresponding cosine values of an array’s elements.
Example
import numpy as np# creating an arrayx = np.array([[1.5, 0], [0.5, 2.5]])# taking the cosine element-wisemyarray = np.cos(x)print(myarray)
Explanation
- Line 1: We import the
numpymodule. - Line 4: We create an array
xusing thearray()method. - Line 7: We implement the
np.cos()function on the array. The result is assigned to a variable,myarray. - Line 9: We print the
myarrayvariable.