Numpy sin – Python NumPy sin() Function

Numpy sin: NumPy has trigonometric functions such as sin, cos, tan, and others. The NumPy trigonometric functions aid in the efficient solution of mathematical trigonometric calculations.

NumPy sin() Function:

Sin function python: To calculate the trigonometric sine of a given angle in radians, use the sin() function of the NumPy module.

Syntax:

numpy.sin(x, out=None)

Parameters

x: This is required. It is an array (array-like) having elements as angles in radians of which the trigonometric sine is calculated.

out: This is optional. It is the location where the result will be saved. It must have a shape that the inputs broadcast to if it is provided. If None or not given, a newly allocated array is returned.

Return Value: 

The sine value of each element of x is returned.

NumPy sin() Function in Python

Example1(In Radians)

Approach:

  • Import numpy module using the import keyword.
  • Pass some random list as an argument to the array() function to create an array.
  • Store it in a variable.
  • Print the above-given array.
  • Convert the above-given array angles into radians using the pi/180 of numpy module.
  • Store it in the same variable.
  • Pass the above radian angles array to the sin() function of the numpy module to get the sin values of the given array angles in radians and print it
  • The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
# Pass some random list as an argument to the array() function to
# create an array. 
# Store it in a variable.
gvn_arry = np.array([30, 45, 120, 180])
# Convert the above given array angles into radians using the pi/180 of 
# numpy module.
# Store it in the same variable.
gvn_arry = gvn_arry*np.pi/180
# Pass the above radian angles array to the sin() function of the 
# numpy module to get the sin values of the given array angles.
print("The given array's sin values = \n", np.sin(gvn_arry))

Output:

The given array's sin values = 
[5.00000000e-01 7.07106781e-01 8.66025404e-01 1.22464680e-16]

Example2(In degrees)

Approach:

  • Import numpy module using the import keyword.
  • Pass some random angle value to the sin() function of the numpy module to get the sine value of the given angle in degrees.
  • Store it in a variable.
  • Print the sine value of the given angle in degrees.
  • The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
# Pass some random angle value to the sin() function of the
# numpy module to get the sine value of the given angle in degrees
# Store it in a variable.
rslt = np.sin(60) 
# Print the sine value of the given angle in degrees
print("The given angle's sine value(degrees) = ", rslt) 

Output:

The given angle's sine value(degrees) = -0.3048106211022167