function max
max(
x: array,
dim?: 0 | 1,
): number

Largest element in array.

Computes the largest element in an array or matrix. For arrays, returns a single value. For matrices, returns the maximum along the specified dimension.

Examples

Simple array maximum

import { assertEquals } from "jsr:@std/assert";

assertEquals(max([1, 3, 2]), 3);

Array with negative values

import { assertEquals } from "jsr:@std/assert";

assertEquals(max([-5, -1, -10]), -1);

Matrix maximum along rows

import { assertEquals } from "jsr:@std/assert";

assertEquals(max([[1, 2], [3, 4]]), [2, 4]);

Parameters

Input array or matrix

optional
dim: 0 | 1

Dimension along which to compute maximum. Default is 0

Return Type

number

Maximum values

Throws

When input is invalid

max(
x: matrix,
dim?: 0 | 1,
): array

Largest element in array.

Computes the largest element in an array or matrix. For arrays, returns a single value. For matrices, returns the maximum along the specified dimension.

Examples

Simple array maximum

import { assertEquals } from "jsr:@std/assert";

assertEquals(max([1, 3, 2]), 3);

Array with negative values

import { assertEquals } from "jsr:@std/assert";

assertEquals(max([-5, -1, -10]), -1);

Matrix maximum along rows

import { assertEquals } from "jsr:@std/assert";

assertEquals(max([[1, 2], [3, 4]]), [2, 4]);

Parameters

Input array or matrix

optional
dim: 0 | 1

Dimension along which to compute maximum. Default is 0

Return Type

Maximum values

Throws

When input is invalid