# ArrayComponents

ArrayComponents[array]

gives an array in which all identical elements of array are replaced by an integer index representing the component in which the element lies.

ArrayComponents[array,level]

finds the identical elements at the specified level in array

ArrayComponents[array,level,rules]

uses a rule or a list of rules for specifying the labels.

# Details

• ArrayComponents returns a label matrix where identical elements are represented by consecutive non-negative integers.
• Occurrences of zeros or None in array are always labeled with zeros.
• ArrayComponents can be used to canonicalize label matrices.

# Background & Context

• ArrayComponents gives an array in which all identical elements of an input array are replaced by an integer index (or "label") representing the component in which the element lies. The indices start at 1 and run consecutively through the number of distinct array elements. A special exception is that any occurrences of 0 and None are labeled with 0.
• ArrayComponents works on lists, two-dimensional arrays, and arrays of arbitrary rank. It can be used to find identical elements at a specified level (e.g. rows in an array). Specific relabeling rules may also be specified.
• ArrayComponents is useful to canonicalize label matrices that are produced from segmentation algorithms. While segmentation algorithms in the Wolfram Language generally return a canonicalized array, functions like DeleteSmallComponents, DeleteBorderComponents, and SelectComponents may delete some indices. ArrayComponents can then be used to relabel using exactly the integers 1 through n for the n remaining components.
• Component measurements and selections such as ComponentMeasurements and SelectComponents can be applied to the result of ArrayComponents for 2D and 3D label matrices.
• ClusteringComponents provides a generalization of ArrayComponents that corresponds to ArrayComponents when the number of clusters is specified as the number of distinct elements in the input array.

# Examples

open allclose all

## Basic Examples(3)

Components in a symbolic array:

Components in the first level of an array:

Label identical elements in a list:

## Scope(3)

ArrayComponents works with arbitrarily nested lists of symbols:

Label all positive integers with a specific label:

Use a specific label for a component:

## Applications(1)

Normalize a label matrix with missing labels:

Wolfram Research (2010), ArrayComponents, Wolfram Language function, https://reference.wolfram.com/language/ref/ArrayComponents.html (updated 2012).

#### Text

Wolfram Research (2010), ArrayComponents, Wolfram Language function, https://reference.wolfram.com/language/ref/ArrayComponents.html (updated 2012).

#### CMS

Wolfram Language. 2010. "ArrayComponents." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. https://reference.wolfram.com/language/ref/ArrayComponents.html.

#### APA

Wolfram Language. (2010). ArrayComponents. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ArrayComponents.html

#### BibTeX

@misc{reference.wolfram_2022_arraycomponents, author="Wolfram Research", title="{ArrayComponents}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/ArrayComponents.html}", note=[Accessed: 27-June-2022 ]}

#### BibLaTeX

@online{reference.wolfram_2022_arraycomponents, organization={Wolfram Research}, title={ArrayComponents}, year={2012}, url={https://reference.wolfram.com/language/ref/ArrayComponents.html}, note=[Accessed: 27-June-2022 ]}