ArrayPad

ArrayPad[array,m]
gives an array with m 0s of padding on every side.

ArrayPad[array,m,padding]
uses the specified padding.

ArrayPad[array,{m,n},]
pads with m elements at the beginning and n elements at the end.

ArrayPad[array,{{m1,n1},{m2,n2},},]
pads with mi, ni elements at level i in array.

Details and OptionsDetails and Options

  • The following forms of padding can be specified:
  • ca constant c
    {c1,c2,}cyclic repetition of constants c1,
    "Extrapolated"polynomial extrapolation of elements
    "Fixed"repetitions of the elements on each boundary
    "Periodic"cyclic repetitions of the complete array
    "Reflected"reflections of the array in the boundary
    "ReflectedDifferences"reflections of the differences between elements
    "Reversed"reversals of the complete array
    "ReversedDifferences"reversals of the differences between elements
    "ReversedNegation"negated reversals of the array
  • The padding value "Fixed" indicates that the elements added at each corner should be copies of the elements at the corners of the original array.
  • "Reversed" indicates that the outermost elements in the array should be repeated as the innermost elements in the padding. "Reflected" specifies that these elements should not be repeated.
  • With the padding value "Extrapolated", the degree of polynomial used is specified by the option InterpolationOrder.
  • ArrayPad pads full arrays of any depth.
  • ArrayPad works with SparseArray objects.
  • ArrayPad[array,-m] removes m elements from each side of array.

ExamplesExamplesopen allclose all

Basic Examples  (5)Basic Examples  (5)

Pad the edges of a list with 0s:

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

Pad the edges of a matrix:

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

Specify different padding on each side:

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

Pad with any expression:

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

Pad according to a named rule:

In[1]:=
Click for copyable input
Out[1]=
Introduced in 2008
(7.0)
Translate this page: