Skip to main content

equal

Test element-wise equality. Inputs are broadcast together.
function equal(x1: ArrayLike, x2: ArrayLike | number): NDArray
NameTypeDefaultDescription
x1ArrayLikeFirst input array.
x2ArrayLikeSecond input array.
Returns: NDArray — Boolean array where each element is true where x1 == x2.
import * as np from 'numpy-ts';

const a = np.array([1, 2, 3]);
const b = np.array([1, 0, 3]);

const result = np.equal(a, b);
// array([true, false, true])

not_equal

Test element-wise inequality. Inputs are broadcast together.
function not_equal(x1: ArrayLike, x2: ArrayLike | number): NDArray
NameTypeDefaultDescription
x1ArrayLikeFirst input array.
x2ArrayLikeSecond input array.
Returns: NDArray — Boolean array where each element is true where x1 != x2.
import * as np from 'numpy-ts';

const a = np.array([1, 2, 3]);
const b = np.array([1, 0, 3]);

const result = np.not_equal(a, b);
// array([false, true, false])

greater

Test element-wise whether x1 > x2. Inputs are broadcast together.
function greater(x1: ArrayLike, x2: ArrayLike | number): NDArray
NameTypeDefaultDescription
x1ArrayLikeFirst input array.
x2ArrayLikeSecond input array.
Returns: NDArray — Boolean array where each element is true where x1 > x2.
import * as np from 'numpy-ts';

const result = np.greater([2, 1, 3], [1, 2, 3]);
// array([true, false, false])

greater_equal

Test element-wise whether x1 >= x2. Inputs are broadcast together.
function greater_equal(x1: ArrayLike, x2: ArrayLike | number): NDArray
NameTypeDefaultDescription
x1ArrayLikeFirst input array.
x2ArrayLikeSecond input array.
Returns: NDArray — Boolean array where each element is true where x1 >= x2.
import * as np from 'numpy-ts';

const result = np.greater_equal([2, 1, 3], [1, 2, 3]);
// array([true, false, true])

less

Test element-wise whether x1 < x2. Inputs are broadcast together.
function less(x1: ArrayLike, x2: ArrayLike | number): NDArray
NameTypeDefaultDescription
x1ArrayLikeFirst input array.
x2ArrayLikeSecond input array.
Returns: NDArray — Boolean array where each element is true where x1 < x2.
import * as np from 'numpy-ts';

const result = np.less([1, 2, 3], [2, 2, 1]);
// array([true, false, false])

less_equal

Test element-wise whether x1 <= x2. Inputs are broadcast together.
function less_equal(x1: ArrayLike, x2: ArrayLike | number): NDArray
NameTypeDefaultDescription
x1ArrayLikeFirst input array.
x2ArrayLikeSecond input array.
Returns: NDArray — Boolean array where each element is true where x1 <= x2.
import * as np from 'numpy-ts';

const result = np.less_equal([1, 2, 3], [2, 2, 1]);
// array([true, true, false])

allclose

Return true if all elements of two arrays are equal within a tolerance.
function allclose(a: ArrayLike, b: ArrayLike | number, rtol?: number, atol?: number): boolean
NameTypeDefaultDescription
aArrayLikeFirst input array.
bArrayLike | numberSecond input array.
rtolnumber1e-5Relative tolerance.
atolnumber1e-8Absolute tolerance.
Returns: booleantrue if |a - b| <= atol + rtol * |b| for all element pairs.
import * as np from 'numpy-ts';

np.allclose([1.0, 1.00001], [1.0, 1.0]);
// true

np.allclose([1.0, 1.1], [1.0, 1.0]);
// false

np.allclose([1.0, 1.1], [1.0, 1.0], 0.2);
// true (increased rtol)

isclose

Return a boolean array where each element is true if the corresponding elements of a and b are equal within a tolerance.
function isclose(a: ArrayLike, b: ArrayLike | number, rtol?: number, atol?: number): NDArray
NameTypeDefaultDescription
aArrayLikeFirst input array.
bArrayLikeSecond input array.
rtolnumber1e-5Relative tolerance.
atolnumber1e-8Absolute tolerance.
equal_nanbooleanfalseIf true, two NaN values are considered equal.
Returns: NDArray — Boolean array of element-wise closeness results.
import * as np from 'numpy-ts';

const result = np.isclose([1.0, 1.00001, NaN], [1.0, 1.0, NaN], 1e-5, 1e-8, true);
// array([true, true, true])

array_equal

Return true if two arrays have the same shape and all elements are equal.
function array_equal(a: ArrayLike, b: ArrayLike, equal_nan?: boolean): boolean
NameTypeDefaultDescription
aArrayLikeFirst input array.
bArrayLikeSecond input array.
equal_nanbooleanfalseIf true, NaN values compare equal.
Returns: booleantrue if both arrays have the same shape and identical elements.
import * as np from 'numpy-ts';

np.array_equal([1, 2, 3], [1, 2, 3]);
// true

np.array_equal([1, 2, 3], [1, 2, 4]);
// false

np.array_equal([1, 2], [[1, 2]]);
// false (different shapes)

array_equiv

Return true if two arrays are broadcastable to the same shape and all elements are equal after broadcasting.
function array_equiv(a: ArrayLike, b: ArrayLike): boolean
NameTypeDefaultDescription
aArrayLikeFirst input array.
bArrayLikeSecond input array.
Returns: booleantrue if the arrays are shape-compatible (broadcastable) and all corresponding elements are equal.
import * as np from 'numpy-ts';

np.array_equiv([1, 2, 3], [1, 2, 3]);
// true

// Broadcasting: scalar 1 is equivalent to [1, 1, 1]
np.array_equiv(1, np.ones([3]));
// true

np.array_equiv([1, 2], [1, 3]);
// false