function transpose
transpose(x: number): number

Transpose a matrix or array.

Transposes the given matrix or array. If the input is a 1D array, it is treated as a row vector and the result is a column vector. If the input is a matrix, the rows and columns are swapped.

Examples

Transpose a 2x3 matrix

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

assertEquals(transpose([[5, 6, 5], [7, 8, -1]]), [[5, 7], [6, 8], [5, -1]]);

Transpose a 1D array (row vector)

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

assertEquals(transpose([5, 6, 3]), [[5], [6], [3]]);

Transpose a single number (scalar)

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

assertEquals(transpose(5), 5);

Transpose a square matrix

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

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

Parameters

x: number

The input array or matrix to transpose.

Return Type

number

The transposed matrix.

Throws

Throws an error if no input is provided.

transpose(x: array): matrix

Transpose a matrix or array.

Transposes the given matrix or array. If the input is a 1D array, it is treated as a row vector and the result is a column vector. If the input is a matrix, the rows and columns are swapped.

Examples

Transpose a 2x3 matrix

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

assertEquals(transpose([[5, 6, 5], [7, 8, -1]]), [[5, 7], [6, 8], [5, -1]]);

Transpose a 1D array (row vector)

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

assertEquals(transpose([5, 6, 3]), [[5], [6], [3]]);

Transpose a single number (scalar)

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

assertEquals(transpose(5), 5);

Transpose a square matrix

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

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

Parameters

The input array or matrix to transpose.

Return Type

The transposed matrix.

Throws

Throws an error if no input is provided.

transpose(x: matrix): matrix

Transpose a matrix or array.

Transposes the given matrix or array. If the input is a 1D array, it is treated as a row vector and the result is a column vector. If the input is a matrix, the rows and columns are swapped.

Examples

Transpose a 2x3 matrix

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

assertEquals(transpose([[5, 6, 5], [7, 8, -1]]), [[5, 7], [6, 8], [5, -1]]);

Transpose a 1D array (row vector)

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

assertEquals(transpose([5, 6, 3]), [[5], [6], [3]]);

Transpose a single number (scalar)

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

assertEquals(transpose(5), 5);

Transpose a square matrix

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

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

Parameters

The input array or matrix to transpose.

Return Type

The transposed matrix.

Throws

Throws an error if no input is provided.

transpose(x: array | matrix): matrix

Transpose a matrix or array.

Transposes the given matrix or array. If the input is a 1D array, it is treated as a row vector and the result is a column vector. If the input is a matrix, the rows and columns are swapped.

Examples

Transpose a 2x3 matrix

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

assertEquals(transpose([[5, 6, 5], [7, 8, -1]]), [[5, 7], [6, 8], [5, -1]]);

Transpose a 1D array (row vector)

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

assertEquals(transpose([5, 6, 3]), [[5], [6], [3]]);

Transpose a single number (scalar)

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

assertEquals(transpose(5), 5);

Transpose a square matrix

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

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

Parameters

The input array or matrix to transpose.

Return Type

The transposed matrix.

Throws

Throws an error if no input is provided.