Skip to main content

isnan

Test element-wise for NaN.
function isnan(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLikeInput array.
Returns: NDArray — Boolean array, true where x is NaN.
import * as np from 'numpy-ts';

const result = np.isnan([1, NaN, Infinity, 0]);
// array([false, true, false, false])

isinf

Test element-wise for positive or negative infinity.
function isinf(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLikeInput array.
Returns: NDArray — Boolean array, true where x is +Inf or -Inf.
import * as np from 'numpy-ts';

const result = np.isinf([1, Infinity, -Infinity, NaN]);
// array([false, true, true, false])

isfinite

Test element-wise for finiteness (not infinity and not NaN).
function isfinite(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLikeInput array.
Returns: NDArray — Boolean array, true where x is finite.
import * as np from 'numpy-ts';

const result = np.isfinite([1, 0, Infinity, NaN, -Infinity]);
// array([true, true, false, false, false])

isneginf

Test element-wise for negative infinity.
function isneginf(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLikeInput array.
Returns: NDArray — Boolean array, true where x is -Infinity.
import * as np from 'numpy-ts';

const result = np.isneginf([1, -Infinity, Infinity, NaN]);
// array([false, true, false, false])

isposinf

Test element-wise for positive infinity.
function isposinf(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLikeInput array.
Returns: NDArray — Boolean array, true where x is +Infinity.
import * as np from 'numpy-ts';

const result = np.isposinf([1, -Infinity, Infinity, NaN]);
// array([false, false, true, false])

iscomplex

Test element-wise whether values are complex (have non-zero imaginary part).
function iscomplex(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLikeInput array.
Returns: NDArray — Boolean array, true where the element has a non-zero imaginary part.
import * as np from 'numpy-ts';

const a = np.array([1, 2, 3], 'complex128');
const result = np.iscomplex(a);
// array([false, false, false])  -- real values stored as complex

iscomplexobj

Return true if the input is a complex-typed array or has complex dtype.
function iscomplexobj(x: ArrayLike): boolean
NameTypeDefaultDescription
xArrayLikeInput to check.
Returns: booleantrue if x is an array with complex dtype (complex64 or complex128).
import * as np from 'numpy-ts';

np.iscomplexobj(np.array([1, 2], 'complex128'));
// true

np.iscomplexobj(np.array([1, 2], 'float64'));
// false

isreal

Test element-wise whether values are real (have zero imaginary part).
function isreal(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLikeInput array.
Returns: NDArray — Boolean array, true where the element has zero imaginary part.
import * as np from 'numpy-ts';

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

isrealobj

Return true if the input is not a complex-typed array.
function isrealobj(x: ArrayLike): boolean
NameTypeDefaultDescription
xArrayLikeInput to check.
Returns: booleantrue if x is not a complex array (i.e., dtype is not complex64 or complex128).
import * as np from 'numpy-ts';

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

np.isrealobj(np.array([1, 2], 'complex128'));
// false

isscalar

Return true if the input is a scalar value (number, boolean, bigint, or string).
function isscalar(val: ArrayLike): boolean
NameTypeDefaultDescription
valArrayLikeValue to test.
Returns: booleantrue if element is a scalar type.
import * as np from 'numpy-ts';

np.isscalar(3.14);      // true
np.isscalar(true);       // true
np.isscalar('hello');    // true
np.isscalar([1, 2, 3]); // false
np.isscalar(np.array([1])); // false

isnat

Test element-wise for Not-a-Time. Since numpy-ts does not implement datetime dtypes, this always returns false for every element. Included for API compatibility with NumPy.
function isnat(x: ArrayLike): NDArray
NameTypeDefaultDescription
xArrayLikeInput array.
Returns: NDArray — Boolean array of all false values (datetime dtypes are not supported).
import * as np from 'numpy-ts';

const result = np.isnat([1, 2, NaN]);
// array([false, false, false])

isfortran

Return true if the array is Fortran-contiguous and not C-contiguous.
function isfortran(x: ArrayLike): boolean
NameTypeDefaultDescription
xArrayLikeInput array.
Returns: booleantrue if the array is Fortran-contiguous (column-major) and not C-contiguous. In numpy-ts, arrays are always C-contiguous, so this typically returns false.
import * as np from 'numpy-ts';

const a = np.array([[1, 2], [3, 4]]);
np.isfortran(a);
// false (numpy-ts arrays are C-contiguous)

iterable

Return true if the input can be iterated over.
function iterable(obj: ArrayLike): boolean
NameTypeDefaultDescription
objArrayLikeValue to test.
Returns: booleantrue if y is iterable (arrays, NDArrays, strings, etc.).
import * as np from 'numpy-ts';

np.iterable([1, 2, 3]);          // true
np.iterable(np.array([1, 2]));   // true
np.iterable(42);                  // false

isdtype

Test whether a dtype belongs to a specified kind or set of dtypes.
function isdtype(dtype: DType, kind: string): boolean
NameTypeDefaultDescription
dtypeDTypeThe dtype to test.
kindstringA dtype kind string (e.g., 'integral', 'real floating', 'numeric').
Returns: booleantrue if dtype matches the specified kind.
import * as np from 'numpy-ts';

np.isdtype('float64', 'real floating');
// true

np.isdtype('int32', 'integral');
// true

np.isdtype('float32', ['float32', 'float64']);
// true

np.isdtype('int32', 'real floating');
// false

real_if_close

If the imaginary part of an array is close to zero, return only the real part. Otherwise, return the input unchanged.
function real_if_close(x: ArrayLike, tol?: number): NDArray
NameTypeDefaultDescription
xArrayLikeInput array.
tolnumber100Tolerance factor. The imaginary part is considered close to zero if max(abs(imag)) < tol * eps where eps is the machine epsilon for the dtype.
Returns: NDArray — Real-valued array if the imaginary part is negligible, otherwise the original array.
import * as np from 'numpy-ts';

// Imaginary part is negligibly small
const a = np.array([1 + 1e-15, 2 + 0, 3 - 1e-15], 'complex128');
const result = np.real_if_close(a);
// array([1, 2, 3])  -- returned as real float64