CenterArray
✖
CenterArray
creates a list of length n with the elements of a at the center and zeros elsewhere.
creates an n1×n2×… array with the array a at the center and zeros 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 allBasic Examples (3)Summary of the most common use cases
Create a list of length 5 with a single 1 at the center:

https://wolfram.com/xid/0b8crjyp6y-felh2

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

https://wolfram.com/xid/0b8crjyp6y-oudv4b

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

https://wolfram.com/xid/0b8crjyp6y-mcyxei

Scope (11)Survey of the scope of standard use cases
Data (9)

https://wolfram.com/xid/0b8crjyp6y-d83lqj


https://wolfram.com/xid/0b8crjyp6y-dxuil4


https://wolfram.com/xid/0b8crjyp6y-4beo7v

Center a matrix to have 3 rows:

https://wolfram.com/xid/0b8crjyp6y-l8iojr

Center a matrix so its dimensions are {3,4}:

https://wolfram.com/xid/0b8crjyp6y-ki6e1g


https://wolfram.com/xid/0b8crjyp6y-sxgvmk


https://wolfram.com/xid/0b8crjyp6y-56crk4

Create an array with more rows and fewer columns:

https://wolfram.com/xid/0b8crjyp6y-e2i8df


https://wolfram.com/xid/0b8crjyp6y-8hlav7


https://wolfram.com/xid/0b8crjyp6y-ri110a


https://wolfram.com/xid/0b8crjyp6y-idsv8p


https://wolfram.com/xid/0b8crjyp6y-bhl3s2

Output Dimensions (1)
Applications (6)Sample problems that can be solved with this function

https://wolfram.com/xid/0b8crjyp6y-v3kuyb

Conform a list of arrays so they have commensurate dimensions:

https://wolfram.com/xid/0b8crjyp6y-t5sgqp

https://wolfram.com/xid/0b8crjyp6y-ceuxgb

https://wolfram.com/xid/0b8crjyp6y-lupn7n

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

https://wolfram.com/xid/0b8crjyp6y-ipkn8r

https://wolfram.com/xid/0b8crjyp6y-oshpkn

Apply a dimension-sensitive operator to the conformed elements:

https://wolfram.com/xid/0b8crjyp6y-jdjlh4

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

https://wolfram.com/xid/0b8crjyp6y-793c8k

Create a sharpening kernel from a lowpass kernel:

https://wolfram.com/xid/0b8crjyp6y-8jcpu6

https://wolfram.com/xid/0b8crjyp6y-b3bjen
Sharpen an image by convolving with the computed kernel:

https://wolfram.com/xid/0b8crjyp6y-6tg2ey

Show a collection of graphs with missing graphics:

https://wolfram.com/xid/0b8crjyp6y-3mkuap

https://wolfram.com/xid/0b8crjyp6y-f8vzjl

By default, GraphicsGrid has empty spaces at the ends:

https://wolfram.com/xid/0b8crjyp6y-eljy58

Properties & Relations (3)Properties of the function, and connections to other functions
If the amount of padding is an odd number, additional padding is placed on the right:

https://wolfram.com/xid/0b8crjyp6y-4ky6dm


https://wolfram.com/xid/0b8crjyp6y-kmuabf

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

https://wolfram.com/xid/0b8crjyp6y-c7dl46


https://wolfram.com/xid/0b8crjyp6y-ibjix7


https://wolfram.com/xid/0b8crjyp6y-rilp2t


https://wolfram.com/xid/0b8crjyp6y-dndmb8

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

https://wolfram.com/xid/0b8crjyp6y-owf8br

https://wolfram.com/xid/0b8crjyp6y-vkhxci


https://wolfram.com/xid/0b8crjyp6y-mcuuy3


https://wolfram.com/xid/0b8crjyp6y-yi3uei

Possible Issues (2)Common pitfalls and unexpected behavior
Padding with nonconstant values may not be possible with empty list inputs:

https://wolfram.com/xid/0b8crjyp6y-80p6dy



https://wolfram.com/xid/0b8crjyp6y-rb7apf

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

https://wolfram.com/xid/0b8crjyp6y-etcv05

https://wolfram.com/xid/0b8crjyp6y-wstysy


https://wolfram.com/xid/0b8crjyp6y-4haf3h


Use a specific target depth instead:

https://wolfram.com/xid/0b8crjyp6y-e9h7jk

Center the resulting array in an array of rank 3:

https://wolfram.com/xid/0b8crjyp6y-5ekuf9

Wolfram Research (2016), CenterArray, Wolfram Language function, https://reference.wolfram.com/language/ref/CenterArray.html.
Text
Wolfram Research (2016), CenterArray, Wolfram Language function, https://reference.wolfram.com/language/ref/CenterArray.html.
Wolfram Research (2016), CenterArray, Wolfram Language function, https://reference.wolfram.com/language/ref/CenterArray.html.
CMS
Wolfram Language. 2016. "CenterArray." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CenterArray.html.
Wolfram Language. 2016. "CenterArray." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CenterArray.html.
APA
Wolfram Language. (2016). CenterArray. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CenterArray.html
Wolfram Language. (2016). CenterArray. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CenterArray.html
BibTeX
@misc{reference.wolfram_2025_centerarray, author="Wolfram Research", title="{CenterArray}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/CenterArray.html}", note=[Accessed: 18-June-2025
]}
BibLaTeX
@online{reference.wolfram_2025_centerarray, organization={Wolfram Research}, title={CenterArray}, year={2016}, url={https://reference.wolfram.com/language/ref/CenterArray.html}, note=[Accessed: 18-June-2025
]}