Skip to main content

around

Round an array to the given number of decimals.
function around(a: ArrayLike, decimals?: number): NDArray
NameTypeDefaultDescription
aArrayLike-Input array.
decimalsnumber0Number of decimal places to round to. 0 rounds to the nearest integer. Negative values round to powers of ten (e.g., -1 rounds to the nearest 10).
Returns: NDArray — Array with each element rounded to the given number of decimals.
import * as np from 'numpy-ts';

const a = np.around(np.array([1.234, 2.567, 3.891]), 2);
// array([1.23, 2.57, 3.89])

const b = np.around(np.array([1.5, 2.5, 3.5]));
// array([2, 2, 4])  -- banker's rounding

const c = np.around(np.array([123, 456, 789]), -2);
// array([100, 500, 800])

round

Alias for around. Round an array to the given number of decimals.
function round(a: ArrayLike, decimals?: number): NDArray
NameTypeDefaultDescription
aArrayLike-Input array.
decimalsnumber0Number of decimal places.
Returns: NDArray — Rounded array.
import * as np from 'numpy-ts';

const a = np.round(np.array([0.123, 4.567, 8.901]), 1);
// array([0.1, 4.6, 8.9])
In the numpy-ts/core entry point, round is exported as round_ to avoid conflicting with the JavaScript built-in Math.round. The main numpy-ts entry point exports it as both round and around.

ceil

Return the ceiling of each element (smallest integer greater than or equal to each value).
function ceil(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLike-Input array.
Returns: NDArray — Element-wise ceiling.
import * as np from 'numpy-ts';

const a = np.ceil(np.array([1.1, 1.9, -1.1, -1.9]));
// array([2, 2, -1, -1])

floor

Return the floor of each element (largest integer less than or equal to each value).
function floor(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLike-Input array.
Returns: NDArray — Element-wise floor.
import * as np from 'numpy-ts';

const a = np.floor(np.array([1.1, 1.9, -1.1, -1.9]));
// array([1, 1, -2, -2])

fix

Round to the nearest integer toward zero.
function fix(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLike-Input array.
Returns: NDArray — Element-wise value rounded toward zero (truncation toward zero).
import * as np from 'numpy-ts';

const a = np.fix(np.array([2.7, -2.7, 0.5, -0.5]));
// array([2, -2, 0, 0])

rint

Round to the nearest integer, element-wise.
function rint(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLike-Input array.
Returns: NDArray — Element-wise value rounded to the nearest integer.
import * as np from 'numpy-ts';

const a = np.rint(np.array([1.2, 1.5, 1.8, 2.5]));
// array([1, 2, 2, 2])

trunc

Return the truncated value of each element (drop the fractional part).
function trunc(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLike-Input array.
Returns: NDArray — Element-wise integer part. Equivalent to fix.
import * as np from 'numpy-ts';

const a = np.trunc(np.array([1.7, -1.7, 0.3, -0.3]));
// array([1, -1, 0, 0])