ArrayReshape

ArrayReshape[list,dims]

arranges the elements of list into a rectangular array with dimensions dims.

ArrayReshape[list,dims,padding]

uses the specified padding if list does not contain enough elements.

Details

  • ArrayReshape always gives a rectangular array of the specified dimensions, ignoring the last elements or adding new elements as necessary.
  • Elements are arranged in the resulting array so that up to length, Flatten[ArrayReshape[list,dims]] is the same as Flatten[list].
  • In ArrayReshape[list,dims,padding], any padding scheme supported by ArrayPad can be specified. The default padding value is 0.
  • ArrayReshape works with SparseArray objects.

Examples

open allclose all

Basic Examples  (4)

Create a 2×3 matrix:

In[1]:=
Click for copyable input
Out[1]=

Reshape a vector into a depth-3 array:

In[1]:=
Click for copyable input
Out[1]=

Use a constant padding value:

In[1]:=
Click for copyable input
Out[1]=

Use rule-based padding values:

In[1]:=
Click for copyable input
Out[1]=

Scope  (1)

Generalizations & Extensions  (1)

Applications  (2)

Properties & Relations  (2)

Possible Issues  (1)

See Also

Flatten  Partition  Fold  ArrayPad  PadRight  Multicolumn

Introduced in 2012
(9.0)