simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

reshape.md (1407B)


      1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
      2 
      3 # Function reshape
      4 
      5 Reshape a multi dimensional array to fit the specified dimensions
      6 
      7 
      8 ## Syntax
      9 
     10 ```js
     11 math.reshape(x, sizes)
     12 ```
     13 
     14 ### Parameters
     15 
     16 Parameter | Type | Description
     17 --------- | ---- | -----------
     18 `x` | Array &#124; Matrix &#124; * | Matrix to be reshaped
     19 `sizes` | number[] | One dimensional array with integral sizes for each dimension. One -1 is allowed as wildcard, which calculates this dimension automatically.
     20 
     21 ### Returns
     22 
     23 Type | Description
     24 ---- | -----------
     25 * &#124; Array &#124; Matrix | A reshaped clone of matrix `x`
     26 
     27 
     28 ### Throws
     29 
     30 Type | Description
     31 ---- | -----------
     32 TypeError | If `sizes` does not contain solely integers
     33 DimensionError | If the product of the new dimension sizes does not equal that of the old ones
     34 
     35 ## Examples
     36 
     37 ```js
     38  math.reshape([1, 2, 3, 4, 5, 6], [2, 3])
     39  // returns Array  [[1, 2, 3], [4, 5, 6]]
     40 
     41  math.reshape([[1, 2], [3, 4]], [1, 4])
     42  // returns Array  [[1, 2, 3, 4]]
     43 
     44  math.reshape([[1, 2], [3, 4]], [4])
     45  // returns Array [1, 2, 3, 4]
     46 
     47  const x = math.matrix([1, 2, 3, 4, 5, 6, 7, 8])
     48  math.reshape(x, [2, 2, 2])
     49  // returns Matrix [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
     50 
     51 math.reshape([1, 2, 3, 4], [-1, 2])
     52 // returns Matrix [[1, 2], [3, 4]]
     53 ```
     54 
     55 
     56 ## See also
     57 
     58 [size](size.md),
     59 [squeeze](squeeze.md),
     60 [resize](resize.md)