Cyforanumera
npm

API reference

np.emath (complex-valued math)

Functions of numpy.emath that switch to complex results outside the real domain.

NameSummary
np.emathThe numpy.emath (numpy.lib.scimath) namespace: math functions that return complex results where the real function is undefined, instead of NaN.
np.emath.sqrtSquare root and logarithms.
np.emath.arcsinInverse sine, cosine and hyperbolic tangent; real input with any |x| > 1 is converted to complex first (same dtype rule as emath.sqrt).
np.emath.lognlogn is the base-n logarithm log(x) / log(n).

np.emath

#
np.emath.{sqrt, log, log2, log10, logn, power, arccos, arcsin, arctanh}

The numpy.emath (numpy.lib.scimath) namespace: math functions that return complex results where the real function is undefined, instead of NaN.

Returns

namespace object

Example

TypeScript
Object.keys(np.emath).length; // => 9

np.emath.sqrt

#
np.emath.sqrt(x) · np.emath.log(x) · np.emath.log2(x) · np.emath.log10(x)

Square root and logarithms. When any real element is negative the whole input is converted to complex first (complex64 for int8/uint8/int16/uint16/float32, otherwise complex128); otherwise the result is real with the ufunc's float dtype. Complex input stays complex.

Parameters

xArrayLike
An NDArray, nested JS array or scalar.

Returns

NDArray (real or complex)

Example

TypeScript
np.emath.sqrt([4, 9]);                  // => [2, 3]
np.real(np.emath.sqrt([-4, 4]));        // => [0, 2]
np.imag(np.emath.sqrt([-4, 4]));        // => [2, 0]
np.emath.sqrt([-4]).dtype.name;         // => "complex128"
np.emath.log10([100]);                  // => [2]
np.imag(np.emath.log(-1)).item();       // => 3.141592653589793
TypeScript declaration
np.emath.sqrt(x: ArrayLike): NDArray
np.emath.log(x: ArrayLike): NDArray
np.emath.log2(x: ArrayLike): NDArray
np.emath.log10(x: ArrayLike): NDArray

np.emath.arcsin

#
np.emath.arcsin(x) · np.emath.arccos(x) · np.emath.arctanh(x)

Inverse sine, cosine and hyperbolic tangent; real input with any |x| > 1 is converted to complex first (same dtype rule as emath.sqrt).

Parameters

xArrayLike
An NDArray, nested JS array or scalar.

Returns

NDArray (real or complex)

Example

TypeScript
np.emath.arcsin([0]);                   // => [0]
np.emath.arccos([2]).dtype.name;        // => "complex128"
np.real(np.emath.arccos([2]));          // => [0]
np.imag(np.emath.arcsin([2])).item();   // => 1.3169578969248166
TypeScript declaration
np.emath.arcsin(x: ArrayLike): NDArray
np.emath.arccos(x: ArrayLike): NDArray
np.emath.arctanh(x: ArrayLike): NDArray

np.emath.logn

#
np.emath.logn(n, x) · np.emath.power(x, p)

logn is the base-n logarithm log(x) / log(n). power is x ** p, complex when a real x is negative; a negative integer p is converted to float64 first, so power([2], -1) is 0.5.

Parameters

n / xArrayLike
An NDArray, nested JS array or scalar.
x / pArrayLike
An NDArray, nested JS array or scalar.

Returns

NDArray

Example

TypeScript
np.emath.logn(2, [4, 8]);               // => [2, 3]
np.emath.power([2, 4], -1);             // => [0.5, 0.25]
np.imag(np.emath.power([-4], 0.5));     // => [2]
TypeScript declaration
np.emath.logn(n: ArrayLike, x: ArrayLike): NDArray
np.emath.power(x: ArrayLike, p: ArrayLike): NDArray