reshape(): matrix
Reshape an array or matrix into a new matrix of given dimensions.
Rearranges elements of an array or matrix into a new shape while preserving order.
Reshape a row vector into a column vector
Reshape a row vector into a column vector
import { assertEquals, assertThrows } from "jsr:@std/assert"; assertEquals(reshape([5, 6, 3], 3, 1), [[5], [6], [3]]);
Reshape a column vector into a row vector
Reshape a column vector into a row vector
import { assertEquals, assertThrows } from "jsr:@std/assert"; assertEquals(reshape([5, 6, 3], 1, 3), [[5, 6, 3]]);
Reshape a 2x3 matrix into a 3x2 matrix (row-wise)
Reshape a 2x3 matrix into a 3x2 matrix (row-wise)
import { assertEquals, assertThrows } from "jsr:@std/assert"; assertEquals(reshape([[-1, 3, -1], [4, 5, 9]], 3, 2), [[-1, 3], [-1, 4], [5, 9]]);
Reshape a 2x3 matrix into a 3x2 matrix (column-wise)
Reshape a 2x3 matrix into a 3x2 matrix (column-wise)
import { assertEquals, assertThrows } from "jsr:@std/assert"; assertEquals(reshape([[-1, 3, -1], [4, 5, 9]], 3, 2, 1), [[-1, 4], [3, 5], [-1, 9]]);
The reshaped matrix.