CenterArray

CenterArray[a,n]

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

CenterArray[a,{n1,n2,}]

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

CenterArray[a,nspec,pad]

uses pad instead of zero for the background.

CenterArray[nspec]

creates an array with a single 1 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 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:

Scope  (11)

Data  (9)

Center a list in a 2D array:

Create a sparse array:

Center a matrix to have 3 rows:

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

Center a ragged array:

Center a mixed input:

Create an array with more rows and fewer columns:

Center a 2D sparse array:

Create a 2D sparse array:

Output Dimensions  (1)

Return a smaller list:

Padding  (1)

The default padding is zero:

Specify a different padding:

Use "Extrapolated" padding instead:

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:

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.

CMS

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

BibTeX

@misc{reference.wolfram_2024_centerarray, author="Wolfram Research", title="{CenterArray}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/CenterArray.html}", note=[Accessed: 21-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_centerarray, organization={Wolfram Research}, title={CenterArray}, year={2016}, url={https://reference.wolfram.com/language/ref/CenterArray.html}, note=[Accessed: 21-December-2024 ]}