
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Get the Trigonometric cosine of an array of angles given in degrees with Python
To find the Trigonometric cosine of an array of angles given in degrees, use the numpy.cos() method in Python Numpy. The method returns the cosine of each element of the 1st parameter x. The 1st parameter, x, is an Angle, in radians (2pi means 360 degrees). Here, it is an array of angles. The 2nd and 3rd parameters are optional.
The 2nd parameter is an ndarray, 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. A tuple must have length equal to the number of outputs.
The 3rd parameter is the condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
Steps
At first, import the required library −
import numpy as np
Following are the Array of angles, finding cos 0, cos 30, cos 45, cos 60, cos 90, cos 180 −
arr = np.array((0., 30., 45., 60., 90., 180.))
Displaying our array −
print("Array...\n",arr)
Get the datatype −
print("\nArray datatype...\n",arr.dtype)
Get the dimensions of the Array −
print("\nArray Dimensions...\n",arr.ndim)
Get the number of elements of the Array −
print("\nNumber of elements in the Array...\n",arr.size)
To find the cosines of an array of angles given in degrees, use the cos() method in Python Numpy −
print("\nResult...",np.cos(arr * np.pi / 180. ))
Example
import numpy as np # To find the Trigonometric cosine of an array of angles given in degrees, use the numpy.cos() method in Python Numpy # The method returns the cosine of each element of the 1st parameter x. print("The Trigonometric cosine of an array of angles...") # Array of angles # finding cos 0, cos 30, cos 45, cos 60, cos 90, cos 180 arr = np.array((0., 30., 45., 60., 90., 180.)) # Display the array print("Array...\n", arr) # Get the type of the array print("\nOur Array type...\n", arr.dtype) # Get the dimensions of the Array print("\nOur Array Dimensions...\n",arr.ndim) # Get the number of elements in the Array print("\nNumber of elements...\n", arr.size) # To find the cosines of an array of angles given in degrees, use the cos() method in Python Numpy print("\nResult...",np.cos(arr * np.pi / 180. ))
Output
The Trigonometric cosine of an array of angles... Array... [ 0. 30. 45. 60. 90. 180.] Our Array type... float64 Our Array Dimensions... 1 Number of elements... 6 Result... [ 1.00000000e+00 8.66025404e-01 7.07106781e-01 5.00000000e-01 6.12323400e-17 -1.00000000e+00]
- Related Articles
- Get the Trigonometric tangent of an array of angles given in degrees with Python
- Get the Trigonometric sines of an array of angles given in degrees in Python
- Get the Trigonometric cosine of an angle in Python
- Get the Trigonometric inverse cosine of the array elements in Python
- Get the Trigonometric inverse cosine in Python
- Get the Trigonometric sin of an angle in Python
- Get the Trigonometric tangent of an angle in Python
- Get the Trigonometric inverse sine of the array elements in Python
- Get the Trigonometric inverse tangent of the array elements in Python
- Get the hyperbolic cosine of a given value in Java
- Get the arc cosine of an angle in Java
- Convert angles from radians to degrees with Python rad2deg()
- Convert angles from degrees to radians with Python deg2rad()
- Compute the Hyperbolic cosine of the array elements in Python
- Compute the inverse Hyperbolic cosine of array elements in Python
