Numpy arcsin – Python NumPy arcsin() Function

Numpy Module:

Numpy arcsin: NumPy is a Python module that is used to work with arrays.

It also has functions for working with linear algebra, the Fourier transform, and matrices.

Travis Oliphant designed NumPy in 2005. It is an open-source project that you are free to use.

NumPy is an abbreviation for Numerical Python.

Uses of NumPy Module:

Arcsin in python: Lists in Python serve the same purpose as arrays, although they are slower to process.

NumPy’s goal is to provide array objects that are up to 50 times faster than ordinary Python lists.

The array object in NumPy is named ndarray, and it comes with a slew of helper methods that make working with ndarray a breeze.

Arrays are often utilized in data science, where speed and resources are critical.

NumPy arcsin() Function:

Numpy arcsin: The NumPy arcsin() function computes the inverse sin of the array elements.

Syntax:

numpy.arcsin(array, out)

Parameters

array: This is required.The items of the array whose inverse sin values will be computed.
out: This is optional. The output array’s shape. It specifies the location where the result will be saved. If given, it must have a shape to which the inputs are broadcast to. If not given or None, a freshly-allocated array is returned.

Return Value:

It returns an array with the inverse sin for each array element, x.

NumPy arcsin() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Import numpy module using the import keyword.
  • Give the list as static input and store it in a variable.
  • Pass the above list as an argument to the array() function to create an array.
  • Store it in another variable.
  • Convert the above-given array angles to radians using numpy.pi/180.
  • Store it in another variable.
  • Get all the sin values of the given array using the numpy.sin() function by passing the given array as an argument to it.
  • Store it in another variable.
  • Get all the inverse sin values of the given array using the numpy.arcsin() function by passing the above sin array as an argument to it and store it in another variable.
  • Print the sin values of the given array.
  • Print the inverse sin values of the given array.
  • Convert the above inverse sin values of the given array from radians to degrees using the degrees() function and print it.
  • The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
# Give the list as static input and store it in a variable.
gvn_lst = [30, 0, 120, 90]
# Pass the above list as an argument to the array() function to create an array.
# Store it in a variable.
gvn_arr = np.array(gvn_lst)
# Convert the above given array angles to radians using numpy.pi/180
# Store it in another variable.
gvn_arr = gvn_arr*np.pi/180

# Get all the sin values of the given array using the numpy.sin() function 
# by passing the given array as an argument to it.
# Store it in another variable.
sin_vals = np.sin(gvn_arr)
# Get all the inverse sin values of the given array using the numpy.arcsin() function 
# by passing the above sin array as an argument to it.
# Store it in another variable.
invrs_sin_vals = np.arcsin(sin_vals)
# Print the sin values of the given array
print("The given array's sin values = ")
print(sin_vals)
# Print the inverse sin values of the given array
print("The given array's inverse sin values(radians) = ")
print(invrs_sin_vals)
# Convert the above inverse sin values of the given array from radians to degrees 
# using the degrees() function and print it.
print("The given array's inverse sin values(degrees) = ")
print(np.degrees(invrs_sin_vals))

Output:

The given array's sin values = 
[0.5 0. 0.8660254 1. ]
The given array's inverse sin values(radians) = 
[0.52359878 0. 1.04719755 1.57079633]
The given array's inverse sin values(degrees) = 
[30. 0. 60. 90.]

Method #2: Using Built-in Functions (User Input)

Approach:

  • Import numpy module using the import keyword.
  • Give the list as user input using the list(),map(),split(),int functions and store it in a variable.
  • Pass the above list as an argument to the array() function to create an array.
  • Store it in another variable.
  • Convert the above-given array angles to radians using numpy.pi/180.
  • Store it in another variable.
  • Get all the sin values of the given array using the numpy.sin() function by passing the given array as an argument to it.
  • Store it in another variable.
  • Get all the inverse sin values of the given array using the numpy.arcsin() function by passing the above sin array as an argument to it and store it in another variable.
  • Print the sin values of the given array.
  • Print the inverse sin values of the given array.
  • Convert the above inverse sin values of the given array from radians to degrees using the degrees() function and print it.
  • The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
# Give the list as user input using the list(),map(),split(),int 
# functions and store it in a variable.
gvn_lst = list(map(int, input(
   'Enter some random List Elements separated by spaces = ').split()))
# Pass the above list as an argument to the array() function to create an array.
# Store it in a variable.
gvn_arr = np.array(gvn_lst)
# Convert the above given array angles to radians using numpy.pi/180
# Store it in another variable.
gvn_arr = gvn_arr*np.pi/180

# Get all the sin values of the given array using the numpy.sin() function 
# by passing the given array as an argument to it.
# Store it in another variable.
sin_vals = np.sin(gvn_arr)
# Get all the inverse sin values of the given array using the numpy.arcsin() function 
# by passing the above sin array as an argument to it.
# Store it in another variable.
invrs_sin_vals = np.arcsin(sin_vals)
# Print the sin values of the given array
print("The given array's sin values = ")
print(sin_vals)
# Print the inverse sin values of the given array
print("The given array's inverse sin values(radians) = ")
print(invrs_sin_vals)
# Convert the above inverse sin values of the given array from radians to degrees 
# using the degrees() function and print it.
print("The given array's inverse sin values(degrees) = ")
print(np.degrees(invrs_sin_vals))

Output:

Enter some random List Elements separated by spaces = 60 120 45 180
The given array's sin values = 
[8.66025404e-01 8.66025404e-01 7.07106781e-01 1.22464680e-16]
The given array's inverse sin values(radians) = 
[1.04719755e+00 1.04719755e+00 7.85398163e-01 1.22464680e-16]
The given array's inverse sin values(degrees) = 
[6.0000000e+01 6.0000000e+01 4.5000000e+01 7.0167093e-15]