> ## Documentation Index
> Fetch the complete documentation index at: https://numpyts.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Type Testing

> Element-wise and whole-object tests for NaN, infinity, finiteness, complex type, scalar type, dtype kind, and more.

### isnan

Test element-wise for NaN.

```typescript theme={null}
function isnan(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input array. |

**Returns:** `NDArray` -- Boolean array, `true` where `x` is `NaN`.

```typescript theme={null}
import * as np from 'numpy-ts';

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

***

### isinf

Test element-wise for positive or negative infinity.

```typescript theme={null}
function isinf(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input array. |

**Returns:** `NDArray` -- Boolean array, `true` where `x` is `+Inf` or `-Inf`.

```typescript theme={null}
import * as np from 'numpy-ts';

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

***

### isfinite

Test element-wise for finiteness (not infinity and not NaN).

```typescript theme={null}
function isfinite(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input array. |

**Returns:** `NDArray` -- Boolean array, `true` where `x` is finite.

```typescript theme={null}
import * as np from 'numpy-ts';

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

***

### isneginf

Test element-wise for negative infinity.

```typescript theme={null}
function isneginf(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input array. |

**Returns:** `NDArray` -- Boolean array, `true` where `x` is `-Infinity`.

```typescript theme={null}
import * as np from 'numpy-ts';

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

***

### isposinf

Test element-wise for positive infinity.

```typescript theme={null}
function isposinf(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input array. |

**Returns:** `NDArray` -- Boolean array, `true` where `x` is `+Infinity`.

```typescript theme={null}
import * as np from 'numpy-ts';

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

***

### iscomplex

Test element-wise whether values are complex (have non-zero imaginary part).

```typescript theme={null}
function iscomplex(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input array. |

**Returns:** `NDArray` -- Boolean array, `true` where the element has a non-zero imaginary part.

```typescript theme={null}
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.

```typescript theme={null}
function iscomplexobj(x: NDArray): boolean
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input to check. |

**Returns:** `boolean` -- `true` if `x` is an array with complex dtype (`complex64` or `complex128`).

```typescript theme={null}
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).

```typescript theme={null}
function isreal(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input array. |

**Returns:** `NDArray` -- Boolean array, `true` where the element has zero imaginary part.

```typescript theme={null}
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.

```typescript theme={null}
function isrealobj(x: NDArray): boolean
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input to check. |

**Returns:** `boolean` -- `true` if `x` is not a complex array (i.e., dtype is not `complex64` or `complex128`).

```typescript theme={null}
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).

```typescript theme={null}
function isscalar(val: unknown): boolean
```

| Name | Type | Default | Description |
| - | - | - | - |
| `val` | `unknown` | -- | Value to test. |

**Returns:** `boolean` -- `true` if `element` is a scalar type.

```typescript theme={null}
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.

```typescript theme={null}
function isnat(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input array. |

**Returns:** `NDArray` -- Boolean array of all `false` values (datetime dtypes are not supported).

```typescript theme={null}
import * as np from 'numpy-ts';

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

***

### isfortran

Return `true` if the array is Fortran-contiguous and not C-contiguous.

```typescript theme={null}
function isfortran(x: NDArray): boolean
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input array. |

**Returns:** `boolean` -- `true` 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`.

```typescript theme={null}
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.

```typescript theme={null}
function iterable(obj: unknown): boolean
```

| Name | Type | Default | Description |
| - | - | - | - |
| `obj` | `unknown` | -- | Value to test. |

**Returns:** `boolean` -- `true` if `y` is iterable (arrays, NDArrays, strings, etc.).

```typescript theme={null}
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.

```typescript theme={null}
function isdtype(dtype: DType, kind: string): boolean
```

| Name | Type | Default | Description |
| - | - | - | - |
| `dtype` | `DType` | -- | The dtype to test. |
| `kind` | `string` | -- | A NumPy dtype kind character: `'i'` (signed integer), `'u'` (unsigned integer), or `'f'` (floating point). |

**Returns:** `boolean` -- `true` if `dtype` matches the specified kind.

```typescript theme={null}
import * as np from 'numpy-ts';

np.isdtype('float64', 'f');
// true

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

np.isdtype('int32', 'f');
// 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.

```typescript theme={null}
function real_if_close(x: NDArray, tol?: number): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input array. |
| `tol` | `number` | `100` | Tolerance 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.

> [!NOTE]
>
> Changed in v1.7.0: input that is already real is handed straight back as a view rather than a copy; the complex branches still allocate. This matches NumPy. Writes to the result reach the input array, so call `.copy()` if you need an independent buffer. `base` is set on exactly the results that alias.

```typescript theme={null}
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
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.