Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
numpy

What is arcsin in NumPy?

Rukhshan Haroon

In mathematics, the inverse of the trigonometric ratio sine is known as arcsin.

In NumPy, a library of the high-level programming language Python, we can use the arcsin function to calculate the arcsin of a given value.

The numpy library must be imported to use the arcsin function:

import numpy as np

Syntax

np.arcsin(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])= <ufunc 'arcsin'>

A universal function (ufunc) is a function that operates on ndarrays in an element-by-element fashion. The arcsin method is a universal function.

Arguments

The arcsin function only accepts the following arguments:

  • x: An array-like structure on the contents of which the arcsin function will be applied.
  • out (optional): The function’s output is stored at this location.
  • where (optional): If set True, a universal function is calculated at this position.
  • casting (optional): This enables the user to decide how the data will be cast. If set as same_kind, safe casting will take place.
  • order (optional): This determines the memory layout of the output. For example, if set as K, the function reads data in the order they are written in memory.
  • dtype(optional): This is the data type of the array.
  • subok(optional): To pass subclasses, subokmust be set as True.

Return value

For real valued inputs, the arcsin function returns an angle in the range [-pi/2, pi/2]. For complex numbers, the range is [-inf, -1] and [1, inf].

If a number can not be represented as a real number or infinity, it returns nan, and the invalid floating point error flag is set.

Note that the range of the sine function is −1 ≤ sin x ≤ 1. Hence, any input out of this range will be treated as invalid by the arcsin function. Since arcsin is the inverse of sine, the range of sine is the domain of arcsin!

Example

The following example demonstrates how the arcsin function responds to complex, real, or invalid inputs.

To use the arcsin function, we first import the numpy library, which contains it.

import numpy as np
print("Complex input:", np.arcsin(3+2j))
print("Invalid input:", np.arcsin(5))
print("Real input:", np.arcsin(.5))

RELATED TAGS

python
numpy

CONTRIBUTOR

Rukhshan Haroon
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring