The numpy.cos()
function in NumPy returns an array’s cosine element-wise.
numpy.cos(x)
The numpy.cos()
function takes the parameter value x
which represents the input array in radians.
The numpy.cos()
function returns the corresponding cosine values of an array’s elements.
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)
numpy
module.x
using the array()
method.np.cos()
function on the array. The result is assigned to a variable, myarray
.myarray
variable.