Get the Trigonometric sines of an array of angles given in degrees in Python


To get the Trigonometric sines of an array of angles given in degrees, use the numpy.sin() method in Python Numpy. The method returns the sine of each element of the 1st parameter x. This is a scalar if is a scalar. 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 (possible only as a keyword argument) 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

The Trigonometric sines of an array of angles. Finding tan 0, tan 30, tan 45, tan 60, tan 90, tan 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 sines of an array of angles given in degrees, use the numpy.sin() method in Python Numpy −

print("\nResult...",np.sin(arr * np.pi / 180. ))

Example

import numpy as np

# To get the Trigonometric sines of an array of angles given in degrees, use the numpy.sin() method in Python Numpy
# The method returns the sine of each element of the 1st parameter x. This is a scalar if is a scalar.

print("The Trigonometric sines of an array of angles...")

# Array of angles
# finding tan 0, tan 30, tan 45, tan 60, tan 90, tan 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 sines of an array of angles given in degrees, use the numpy.sin() method in Python Numpy
print("\nResult...",np.sin(arr * np.pi / 180. ))

Output

The Trigonometric sines 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... [0.00000000e+00 5.00000000e-01 7.07106781e-01 8.66025404e-01
1.00000000e+00 1.22464680e-16]

Updated on: 25-Feb-2022

245 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements