CenterArray

CenterArray[a,n]

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

CenterArray[a,{n1,n2,}]

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

CenterArray[a,nspec,pad]

uses pad instead of 0 for the background.

CenterArray[nspec]

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

Details

  • 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.

Examples

open allclose all

Basic Examples  (3)

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

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

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

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

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

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

Applications  (6)

Properties & Relations  (3)

Possible Issues  (2)

See Also

ArrayPad  PadLeft  PadRight  BoxMatrix  ArrayReshape

Introduced in 2016
(11.0)