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

# Other Math

> Clipping, element-wise min/max, NaN handling, interpolation, special functions, and complex number operations.

### clip

Clip (limit) the values in an array to a given range.

```typescript theme={null}
function clip(a: NDArray, a_min: NDArray | number | null, a_max: NDArray | number | null): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `a` | `NDArray` | - | Input array. |
| `a_min` | `number \| null` | - | Minimum value. Elements below this are set to `a_min`. Pass `null` to skip the lower bound. |
| `a_max` | `number \| null` | - | Maximum value. Elements above this are set to `a_max`. Pass `null` to skip the upper bound. |

**Returns:** `NDArray` -- Array with values clipped to `[a_min, a_max]`.

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

const a = np.clip(np.array([1, 5, 10, 15, 20]), 3, 12);
// array([3, 5, 10, 12, 12])

// One-sided clipping
const b = np.clip(np.array([-5, 0, 5, 10]), 0, null);
// array([0, 0, 5, 10])
```

```typescript Core theme={null}
import { clip, array } from 'numpy-ts/core';

const a = clip(array([1, 5, 10, 15, 20]), 3, 12);
```

***

### maximum

Element-wise maximum of two arrays. Propagates NaN.

```typescript theme={null}
function maximum(x1: NDArray, x2: NDArray | number): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x1` | `NDArray` | - | First input array. |
| `x2` | `NDArray \| number` | - | Second input array or scalar. |

**Returns:** `NDArray` -- Element-wise maximum. If either element is NaN, the result is NaN.

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

const a = np.maximum(np.array([1, 5, 3]), np.array([4, 2, 6]));
// array([4, 5, 6])

const b = np.maximum(np.array([-1, 0, 1]), 0);
// array([0, 0, 1])  -- ReLU-like operation
```

```typescript Core theme={null}
import { maximum, array } from 'numpy-ts/core';

const a = maximum(array([1, 5, 3]), array([4, 2, 6]));
```

***

### minimum

Element-wise minimum of two arrays. Propagates NaN.

```typescript theme={null}
function minimum(x1: NDArray, x2: NDArray | number): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x1` | `NDArray` | - | First input array. |
| `x2` | `NDArray \| number` | - | Second input array or scalar. |

**Returns:** `NDArray` -- Element-wise minimum. If either element is NaN, the result is NaN.

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

const a = np.minimum(np.array([1, 5, 3]), np.array([4, 2, 6]));
// array([1, 2, 3])
```

```typescript Core theme={null}
import { minimum, array } from 'numpy-ts/core';

const a = minimum(array([1, 5, 3]), array([4, 2, 6]));
```

***

### fmax

Element-wise maximum of two arrays, ignoring NaN. If one element is NaN, the other is returned.

```typescript theme={null}
function fmax(x1: NDArray, x2: NDArray | number): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x1` | `NDArray` | - | First input array. |
| `x2` | `NDArray \| number` | - | Second input array or scalar. |

**Returns:** `NDArray` -- Element-wise maximum, ignoring NaN.

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

const a = np.fmax(np.array([1, NaN, 3]), np.array([NaN, 2, NaN]));
// array([1, 2, 3])  -- NaN ignored in each pair
```

```typescript Core theme={null}
import { fmax, array } from 'numpy-ts/core';

const a = fmax(array([1, NaN, 3]), array([NaN, 2, NaN]));
```

***

### fmin

Element-wise minimum of two arrays, ignoring NaN.

```typescript theme={null}
function fmin(x1: NDArray, x2: NDArray | number): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x1` | `NDArray` | - | First input array. |
| `x2` | `NDArray \| number` | - | Second input array or scalar. |

**Returns:** `NDArray` -- Element-wise minimum, ignoring NaN.

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

const a = np.fmin(np.array([1, NaN, 3]), np.array([NaN, 2, NaN]));
// array([1, 2, 3])
```

```typescript Core theme={null}
import { fmin, array } from 'numpy-ts/core';

const a = fmin(array([1, NaN, 3]), array([NaN, 2, NaN]));
```

***

### nan\_to\_num

Replace NaN with zero and infinity with large finite numbers (or specified values).

```typescript theme={null}
function nan_to_num(
  x: NDArray,
  nan?: number,
  posinf?: number,
  neginf?: number
): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | - | Input array. |
| `nan` | `number` | `0.0` | Value to replace NaN with. |
| `posinf` | `number` | `undefined` | Value to replace positive infinity. Defaults to a very large finite number. |
| `neginf` | `number` | `undefined` | Value to replace negative infinity. Defaults to a very large negative finite number. |

**Returns:** `NDArray` -- Array with NaN/Inf replaced.

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

const a = np.nan_to_num(np.array([1, NaN, Infinity, -Infinity]));
// array([1, 0, 1.7977e+308, -1.7977e+308])

const b = np.nan_to_num(np.array([NaN, Infinity]), -1, 999);
// array([-1, 999])
```

```typescript Core theme={null}
import { nan_to_num, array } from 'numpy-ts/core';

const a = nan_to_num(array([1, NaN, Infinity, -Infinity]));
```

***

### interp

One-dimensional linear interpolation for monotonically increasing sample points.

```typescript theme={null}
function interp(
  x: NDArray,
  xp: NDArray,
  fp: NDArray,
  left?: number,
  right?: number,
  period?: number
): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | - | x-coordinates at which to evaluate the interpolation. |
| `xp` | `NDArray` | - | x-coordinates of the data points (must be increasing unless `period` is given). |
| `fp` | `NDArray` | - | y-coordinates of the data points (same length as `xp`). |
| `left` | `number` | `fp[0]` | Value to return for `x < xp[0]`. Ignored when `period` is given. |
| `right` | `number` | `fp[fp.length - 1]` | Value to return for `x > xp[-1]`. Ignored when `period` is given. |
| `period` | `number` | `undefined` | If given, treat `xp` as periodic with this period. `x` and `xp` are normalized into `[0, period)`, `xp` is sorted internally, and a wrap-around copy of the first/last sample is appended so any normalized `x` lies in range. `left`/`right` are ignored. Throws if `period === 0`. |

**Returns:** `NDArray` -- Interpolated values at each point in `x`.

Existing 5-argument callers are unaffected.

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

const xp = np.array([0, 1, 2, 3]);
const fp = np.array([0, 10, 20, 30]);
const x = np.array([0.5, 1.5, 2.5]);

const y = np.interp(x, xp, fp);
// array([5, 15, 25])

// Periodic interpolation on angle/phase data (period = 2*pi)
const angles = np.array([0, Math.PI / 2, Math.PI, (3 * Math.PI) / 2]);
const values = np.array([0, 1, 0, -1]);
np.interp(np.array([-Math.PI / 4, (9 * Math.PI) / 4]), angles, values, undefined, undefined, 2 * Math.PI);
// wraps inputs into [0, 2*pi) before interpolating
```

```typescript Core theme={null}
import { interp, array } from 'numpy-ts/core';

const xp = array([0, 1, 2, 3]);
const fp = array([0, 10, 20, 30]);
const y = interp(array([0.5, 1.5]), xp, fp);
```

***

### sinc

Return the normalized sinc function: `sin(pi*x) / (pi*x)`. The sinc function is `1` at `x = 0`.

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

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

**Returns:** `NDArray` -- Element-wise `sin(pi*x) / (pi*x)`.

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

const a = np.sinc(np.array([0, 0.5, 1, 1.5, 2]));
// array([1, 0.6366..., 0, -0.2122..., 0])
```

```typescript Core theme={null}
import { sinc, array } from 'numpy-ts/core';

const a = sinc(array([0, 0.5, 1, 1.5, 2]));
```

***

### i0

Modified Bessel function of the first kind, order 0.

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

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | - | Input array (argument of the Bessel function). |

**Returns:** `NDArray` -- Element-wise modified Bessel function I\_0(x).

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

const a = np.i0(np.array([0, 1, 2]));
// array([1, 1.2661..., 2.2796...])
```

```typescript Core theme={null}
import { i0, array } from 'numpy-ts/core';

const a = i0(array([0, 1, 2]));
```

***

### unwrap

Unwrap by changing deltas between values to their `2*pi` complement. Useful for unwrapping radian phase data.

```typescript theme={null}
function unwrap(
  p: NDArray,
  discont?: number,
  axis?: number,
  period?: number
): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `p` | `NDArray` | - | Input array of phase angles. |
| `discont` | `number` | `Math.PI` | Maximum discontinuity between consecutive values. Jumps larger than this are wrapped. |
| `axis` | `number` | `-1` | Axis along which to unwrap. |
| `period` | `number` | `2 * Math.PI` | Wrapping period. |

**Returns:** `NDArray` -- Unwrapped array.

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

// Phase angles with wrapping
const phase = np.array([0, 1, 2, 3, -3, -2, -1, 0]);
const unwrapped = np.unwrap(phase);
// Discontinuities are removed
```

```typescript Core theme={null}
import { unwrap, array } from 'numpy-ts/core';

const phase = array([0, 1, 2, 3, -3, -2, -1, 0]);
const unwrapped = unwrap(phase);
```

***

### real

Return the real part of each element. For real-valued arrays there is nothing to extract, so the input is handed back as a view.

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

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | - | Input array (real or complex). |

**Returns:** `NDArray` -- The real part of each element.

> [!NOTE]
>
> Changed in v1.7.0: a real-valued input now comes back as a view rather than a copy, matching NumPy. Writes to the result reach the input array. Complex input still allocates. Check `base` to tell the two apart -- it is set only when the result aliases.

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

const a = np.array([new Complex(1, 2), new Complex(3, 4)]);
const r = np.real(a);
// array([1, 3])
```

```typescript Core theme={null}
import { real, array } from 'numpy-ts/core';
import { Complex } from 'numpy-ts/core';

const a = array([new Complex(1, 2), new Complex(3, 4)]);
const r = real(a);
```

***

### imag

Return the imaginary part of each element. For real-valued arrays, returns zeros.

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

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | - | Input array (real or complex). |

**Returns:** `NDArray` -- The imaginary part of each element.

> [!NOTE]
>
> Unlike `real`, this always allocates for real-valued input -- the zeros it returns are a fresh buffer with no `base`, so writing to the result never touches the input.

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

const a = np.array([new Complex(1, 2), new Complex(3, 4)]);
const i = np.imag(a);
// array([2, 4])
```

```typescript Core theme={null}
import { imag, array } from 'numpy-ts/core';
import { Complex } from 'numpy-ts/core';

const a = array([new Complex(1, 2), new Complex(3, 4)]);
const i = imag(a);
```

***

### conj

Return the complex conjugate, element-wise. For each element `a + bi`, returns `a - bi`. Also available as the alias `conjugate`.

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

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | - | Input array (real or complex). |

**Returns:** `NDArray` -- Complex conjugate of each element.

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

const a = np.array([new Complex(1, 2), new Complex(3, -4)]);
const c = np.conj(a);
// complex128 array: [(1-2j), (3+4j)]

// Alias
const c2 = np.conjugate(a);
```

```typescript Core theme={null}
import { conj, array } from 'numpy-ts/core';
// or: import { conjugate } from 'numpy-ts/core';

import { Complex } from 'numpy-ts/core';

const a = array([new Complex(1, 2)]);
const c = conj(a);
```

***

### angle

Return the angle (argument) of complex numbers.

```typescript theme={null}
function angle(x: NDArray, deg?: boolean): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | - | Input array of complex numbers. |
| `deg` | `boolean` | `false` | If `true`, return angles in degrees instead of radians. |

**Returns:** `NDArray` -- The counterclockwise angle from the positive real axis, in radians (or degrees if `deg` is `true`).

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

const a = np.array([new Complex(1, 1), new Complex(0, 1), new Complex(-1, 0)]);
const angles = np.angle(a);
// array([0.7854..., 1.5708..., 3.1416...])  -- pi/4, pi/2, pi

const degrees = np.angle(a, true);
// array([45, 90, 180])
```

```typescript Core theme={null}
import { angle, array } from 'numpy-ts/core';
import { Complex } from 'numpy-ts/core';

const a = array([new Complex(1, 1), new Complex(0, 1)]);
const angles = angle(a);
```


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