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

# Comparison

> Element-wise comparison functions that return boolean arrays, plus whole-array equality and closeness tests.

### equal

Test element-wise equality. Inputs are broadcast together.

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

| Name | Type | Default | Description |
| - | - | - | - |
| `x1` | `NDArray` | -- | First input array. |
| `x2` | `NDArray` | -- | Second input array. |

**Returns:** `NDArray` -- Boolean array where each element is `true` where `x1 == x2`.

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

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

| Name | Type | Default | Description |
| - | - | - | - |
| `x1` | `NDArray` | -- | First input array. |
| `x2` | `NDArray` | -- | Second input array. |

**Returns:** `NDArray` -- Boolean array where each element is `true` where `x1 != x2`.

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

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

| Name | Type | Default | Description |
| - | - | - | - |
| `x1` | `NDArray` | -- | First input array. |
| `x2` | `NDArray` | -- | Second input array. |

**Returns:** `NDArray` -- Boolean array where each element is `true` where `x1 > x2`.

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

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

***

### greater\_equal

Test element-wise whether `x1 >= x2`. Inputs are broadcast together.

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

| Name | Type | Default | Description |
| - | - | - | - |
| `x1` | `NDArray` | -- | First input array. |
| `x2` | `NDArray` | -- | Second input array. |

**Returns:** `NDArray` -- Boolean array where each element is `true` where `x1 >= x2`.

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

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

***

### less

Test element-wise whether `x1 < x2`. Inputs are broadcast together.

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

| Name | Type | Default | Description |
| - | - | - | - |
| `x1` | `NDArray` | -- | First input array. |
| `x2` | `NDArray` | -- | Second input array. |

**Returns:** `NDArray` -- Boolean array where each element is `true` where `x1 < x2`.

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

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

***

### less\_equal

Test element-wise whether `x1 <= x2`. Inputs are broadcast together.

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

| Name | Type | Default | Description |
| - | - | - | - |
| `x1` | `NDArray` | -- | First input array. |
| `x2` | `NDArray` | -- | Second input array. |

**Returns:** `NDArray` -- Boolean array where each element is `true` where `x1 <= x2`.

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

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

***

### allclose

Return `true` if all elements of two arrays are equal within a tolerance.

```typescript theme={null}
function allclose(a: NDArray, b: NDArray | number, rtol?: number, atol?: number): boolean
```

| Name | Type | Default | Description |
| - | - | - | - |
| `a` | `NDArray` | -- | First input array. |
| `b` | `NDArray \| number` | -- | Second input array. |
| `rtol` | `number` | `1e-5` | Relative tolerance. |
| `atol` | `number` | `1e-8` | Absolute tolerance. |

**Returns:** `boolean` -- `true` if `|a - b| <= atol + rtol * |b|` for all element pairs.

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

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

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

np.allclose(np.array([1.0, 1.1]), np.array([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.

```typescript theme={null}
function isclose(a: NDArray, b: NDArray | number, rtol?: number, atol?: number): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `a` | `NDArray` | -- | First input array. |
| `b` | `NDArray` | -- | Second input array. |
| `rtol` | `number` | `1e-5` | Relative tolerance. |
| `atol` | `number` | `1e-8` | Absolute tolerance. |

**Returns:** `NDArray` -- Boolean array of element-wise closeness results.

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

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

***

### array\_equal

Return `true` if two arrays have the same shape and all elements are equal.

```typescript theme={null}
function array_equal(a: NDArray, b: NDArray, equal_nan?: boolean): boolean
```

| Name | Type | Default | Description |
| - | - | - | - |
| `a` | `NDArray` | -- | First input array. |
| `b` | `NDArray` | -- | Second input array. |
| `equal_nan` | `boolean` | `false` | If `true`, `NaN` values compare equal. |

**Returns:** `boolean` -- `true` if both arrays have the same shape and identical elements.

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

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

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

np.array_equal(np.array([1, 2]), np.array([[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.

```typescript theme={null}
function array_equiv(a: NDArray, b: NDArray): boolean
```

| Name | Type | Default | Description |
| - | - | - | - |
| `a` | `NDArray` | -- | First input array. |
| `b` | `NDArray` | -- | Second input array. |

**Returns:** `boolean` -- `true` if the arrays are shape-compatible (broadcastable) and all corresponding elements are equal.

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

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

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

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


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