Skip to content

Latest commit

 

History

History
64 lines (42 loc) · 1.18 KB

reshape.md

File metadata and controls

64 lines (42 loc) · 1.18 KB

reshape

Reshape nested values into a new dimension layout.

API

Numeric.shape.reshape(input, shape, order = 'C')

Rebuilds the array with the requested dimensions.

  • Parameters:
    • input: Nested array to reshape
    • shape: Target dimensions of the reshaped array
    • order: Memory layout order, row-major or column-major
  • Returns: Array holding the reshaped values
  • NumPy: Covers np.reshape, ndarray.reshape through a single Numerix method.

Examples

Flatten a matrix into a vector

import Numeric from '@neabyte/numerix'

const values = Numeric.shape.reshape([[1, 2], [3, 4]], [4])

console.log(values)
// [1,2,3,4]

Build a matrix from a vector

import Numeric from '@neabyte/numerix'

const matrix = Numeric.shape.reshape([1, 2, 3, 4], [2, 2])

console.log(matrix)
// [[1,2],[3,4]]

Build a three dimensional array

import Numeric from '@neabyte/numerix'

const values = Numeric.shape.reshape([1, 2, 3, 4], [2, 1, 2])

console.log(values)
// [[[1,2]],[[3,4]]]

Reshape into a single row

import Numeric from '@neabyte/numerix'

const matrix = Numeric.shape.reshape([1, 2, 3], [1, 3])

console.log(matrix)
// [[1,2,3]]