Skip to main content
All functions in this section are element-wise unary operations unless noted otherwise.

exp

Compute the exponential e**x for each element.
function exp(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLike-Input array (exponents).
Returns: NDArray — Element-wise e**x.
import * as np from 'numpy-ts';

const a = np.exp(np.array([0, 1, 2]));
// array([1, 2.71828..., 7.38906...])

const b = np.exp(np.array([np.log(2)]));
// array([2])

exp2

Compute 2**x for each element.
function exp2(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLike-Input array (exponents).
Returns: NDArray — Element-wise 2**x.
import * as np from 'numpy-ts';

const a = np.exp2(np.array([0, 1, 2, 3, 8]));
// array([1, 2, 4, 8, 256])

expm1

Compute exp(x) - 1 for each element. More accurate than exp(x) - 1 for small values of x.
function expm1(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLike-Input array.
Returns: NDArray — Element-wise e**x - 1.
import * as np from 'numpy-ts';

// More accurate than np.exp(x) - 1 for small x
const a = np.expm1(np.array([1e-10, 0, 1]));
// array([1e-10, 0, 1.71828...])

log

Natural logarithm, element-wise. The natural log is the inverse of the exponential function: if y = exp(x), then x = log(y).
function log(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLike-Input array. Values must be positive.
Returns: NDArray — Element-wise natural logarithm (base e).
import * as np from 'numpy-ts';

const a = np.log(np.array([1, Math.E, Math.E ** 2]));
// array([0, 1, 2])

log2

Base-2 logarithm, element-wise.
function log2(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLike-Input array. Values must be positive.
Returns: NDArray — Element-wise base-2 logarithm.
import * as np from 'numpy-ts';

const a = np.log2(np.array([1, 2, 4, 8, 256]));
// array([0, 1, 2, 3, 8])

log10

Base-10 logarithm, element-wise.
function log10(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLike-Input array. Values must be positive.
Returns: NDArray — Element-wise base-10 logarithm.
import * as np from 'numpy-ts';

const a = np.log10(np.array([1, 10, 100, 1000]));
// array([0, 1, 2, 3])

log1p

Natural logarithm of 1 + x, element-wise. More accurate than log(1 + x) for small values of x.
function log1p(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLike-Input array. Values must be greater than -1.
Returns: NDArray — Element-wise ln(1 + x).
import * as np from 'numpy-ts';

// More accurate than np.log(1 + x) for small x
const a = np.log1p(np.array([1e-10, 0, 1]));
// array([1e-10, 0, 0.69315...])

logaddexp

Logarithm of the sum of exponentiations: log(exp(x1) + exp(x2)). Useful for computing log-probabilities. This is a binary operation.
function logaddexp(x1: ArrayLike, x2: ArrayLike | number): NDArray
NameTypeDefaultDescription
x1ArrayLike-First input array.
x2ArrayLike | number-Second input array or scalar.
Returns: NDArray — Element-wise log(exp(x1) + exp(x2)).
import * as np from 'numpy-ts';

// Adding log-probabilities
const logp1 = np.array([-1, -2, -3]);
const logp2 = np.array([-1, -3, -5]);
const result = np.logaddexp(logp1, logp2);

logaddexp2

Logarithm base 2 of the sum of exponentiations: log2(2**x1 + 2**x2). This is a binary operation.
function logaddexp2(x1: ArrayLike, x2: ArrayLike | number): NDArray
NameTypeDefaultDescription
x1ArrayLike-First input array.
x2ArrayLike | number-Second input array or scalar.
Returns: NDArray — Element-wise log2(2**x1 + 2**x2).
import * as np from 'numpy-ts';

const a = np.logaddexp2(np.array([1, 2, 3]), np.array([1, 2, 3]));
// array([2, 3, 4])  -- log2(2^1 + 2^1) = log2(4) = 2, etc.