creates a list of length n with the elements of a at the center and 0s elsewhere.


creates an n1×n2× array with the array a at the center and 0s elsewhere.


uses pad instead of 0 for the background.


creates an array with a single 1 at the center and 0s elsewhere.


  • The input a can be a list, full array, ragged array, or any form of array, such as a SparseArray object.
  • CenterArray always generates a full array.
  • CenterArray[a,nspec,pad,SparseArray] creates a SparseArray object.
  • CenterArray[expr,] is equivalent to CenterArray[{expr},] if expr is not a list.
  • CenterArray[a,n] attempts if possible to put equal padding on both sides of a. If this is not possible, additional padding is placed on the right.
  • In the form CenterArray[a,{n1,n2,}], any of the ni can be Inherited, in which case it is assumed to be the corresponding dimension of a, and no padding is added at this level.
  • If the resulting array has a higher rank, a is centered at the deepest level.
  • For possible settings of padding value pad, see the reference page for ArrayPad.


open allclose all

Basic Examples  (3)

Create a list of length 5 with a single 1 at the center:

Create a list of length 5 with the specified element at the center:

Place an element at the center of a 2D array:

Applications  (6)

Crop the center of an array:

Conform a list of arrays so they have commensurate dimensions:

Conform elements of a list so they are all of length 3:

Apply a dimension-sensitive operator to the conformed elements:

Make a full array from a ragged list of full arrays:

Create a sharpening kernel from a lowpass kernel:

Sharpen an image by convolving with the computed kernel:

Show a collection of graphs with missing graphics:

By default, GraphicsGrid has empty spaces at the ends:

Properties & Relations  (3)

If the amount of padding is an odd number, additional padding is placed on the right:

2D input:

The background value of sparse arrays is preserved, irrespective of the specified padding value:

The precision of the result is the minimum of the precisions of the input array and the padding value:

Possible Issues  (2)

Padding with nonconstant values may not be possible with empty list inputs:

Use constant padding instead:

This ragged input cannot be centered because it is not a list of full arrays with the same depths:

Use a specific target depth instead:

Center the resulting array in an array of rank 3:

Introduced in 2016