Skip to main content

logical_and

Compute element-wise logical AND. Inputs are broadcast together. Truthy values (non-zero) are treated as true.
function logical_and(x1: ArrayLike, x2: ArrayLike | number): NDArray
NameTypeDefaultDescription
x1ArrayLikeFirst input array.
x2ArrayLikeSecond input array.
Returns: NDArray — Boolean array where each element is x1[i] && x2[i].
import * as np from 'numpy-ts';

const result = np.logical_and([true, true, false, false], [true, false, true, false]);
// array([true, false, false, false])

// Works with numeric arrays (0 is false, non-zero is true)
np.logical_and([1, 0, 3], [1, 1, 0]);
// array([true, false, false])

logical_or

Compute element-wise logical OR. Inputs are broadcast together.
function logical_or(x1: ArrayLike, x2: ArrayLike | number): NDArray
NameTypeDefaultDescription
x1ArrayLikeFirst input array.
x2ArrayLikeSecond input array.
Returns: NDArray — Boolean array where each element is x1[i] || x2[i].
import * as np from 'numpy-ts';

const result = np.logical_or([true, true, false, false], [true, false, true, false]);
// array([true, true, true, false])

np.logical_or([0, 0, 1], [0, 1, 0]);
// array([false, true, true])

logical_not

Compute element-wise logical NOT.
function logical_not(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLikeInput array.
Returns: NDArray — Boolean array where each element is !x[i].
import * as np from 'numpy-ts';

const result = np.logical_not([true, false, true]);
// array([false, true, false])

np.logical_not([0, 1, -1, 0.0]);
// array([true, false, false, true])

logical_xor

Compute element-wise logical XOR. Inputs are broadcast together.
function logical_xor(x1: ArrayLike, x2: ArrayLike | number): NDArray
NameTypeDefaultDescription
x1ArrayLikeFirst input array.
x2ArrayLikeSecond input array.
Returns: NDArray — Boolean array where each element is true when exactly one of x1[i] or x2[i] is truthy.
import * as np from 'numpy-ts';

const result = np.logical_xor([true, true, false, false], [true, false, true, false]);
// array([false, true, true, false])

np.logical_xor([1, 0, 1], [1, 1, 0]);
// array([false, true, true])