.cos()
Anonymous contributor
Published Jun 20, 2024Updated Sep 7, 2024
Contribute to Docs
In NumPy, the .cos()
function computes the cosine of each element in an array. This trigonometric function is essential for various mathematical computations, especially in physics, engineering, computer graphics, signal processing, and more.
Syntax
numpy.cos(array, out = None, dtype = None)
array
: The Python library that provides support for large, multi-dimensional arrays and matrices, along with a large collection of mathematical functions to operate on these arrays.out
: Optional. This is an alternative output array in which to place the result. It must have the same shape as the expected output. If not provided, a new array is returned.dtype
: Optional. The desired data type for the output array. If not provided, the data type of the input array is used.
Example
The below example shows the .cos()
function in use:
import numpy as np# A single angle in radiansangle = np.pi / 4# Calculate the cosine of the anglecos_value = np.cos(angle)print("Angle (radians):", angle)print("Cosine value:", cos_value)
The above code generates the output as below:
Angle (radians): 0.7853981633974483Cosine value: 0.7071067811865476
Codebyte Example
Run the following code to understand how the .cos()
function works:
All contributors
- Anonymous contributor
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.