function flipud
flipud(x: number | matrix): number | matrix

Flip a matrix upside down.

Reverses the order of the rows in the input matrix, flipping it upside down.

Examples

Flip a 2D matrix upside down

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

assertEquals(flipud([[1, 4], [2, 5], [3, 6]]), [[3, 2, 1], [6, 5, 4]]);

Flip a single number (should return the number itself)

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

assertEquals(flipud(5), 5);

Flip a simple 2D matrix

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

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

Parameters

x: number | matrix

The input array or matrix

Return Type

number | matrix

The matrix with its rows flipped upside down

Throws

If no input is provided or input is invalid