function cat
cat(
dim: number,
...args: (
number
| array
| matrix
)[]
,
): array | matrix

Concatenates arrays and matrices along the specified dimension.

Concatenates arrays and matrices along the specified dimension. Supports vertical (0) and horizontal (1) concatenation.

Examples

Vertical Concatenation (dim = 0) with numbers

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

assertEquals(cat(0, 1, 2, 3, 4), [[1], [2], [3], [4]]);

Vertical Concatenation (dim = 0) with arrays

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

assertEquals(cat(0, [5, 6, 3], [0.5, -3, 2.3]), [[5, 6, 3], [0.5, -3, 2.3]]);

Vertical Concatenation (dim = 0) with matrix and array

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

const result3 = cat(0, [[5, 6, 5], [7, 8, -1]], [5, 6, 3]);
assertEquals(result3, [[5, 6, 5], [7, 8, -1], [5, 6, 3]]);

Horizontal Concatenation (dim = 1) with numbers

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

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

Horizontal Concatenation (dim = 1) with arrays

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

assertEquals(cat(1, [5, 6, 3], [0.5, -3, 2.3]), [[5, 6, 3, 0.5, -3, 2.3]]);

Horizontal Concatenation (dim = 1) with matrix and arrays

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

const result6 = cat(1, [[2, 3, 4]], [5, 6, 3], [0.5, -3, 2.3]);
assertEquals(result6, [[2, 3, 4, 5, 6, 3, 0.5, -3, 2.3]]);

Parameters

dim: number

The dimension along which to concatenate (0: rows, 1: columns)

...args: (
number
| array
| matrix
)[]

Return Type

The concatenated array or matrix

Throws

If not enough input arguments are provided or if dimensions do not match for concatenation