FlattenLayer

FlattenLayer[]

represents a net layer that flattens any input array into a vector.

FlattenLayer[n]

represents a net layer that flattens its input to level n.

FlattenLayer[{{s11,s12,},{s21,s22,},}]

represents a net layer that flattens its input by combining all levels sij to make each level i in the result.

Details and Options

Examples

open allclose all

Basic Examples  (2)

Create a FlattenLayer:

Create a FlattenLayer with specified input dimensions:

Apply the layer to a matrix:

Scope  (4)

Create a FlattenLayer that flattens the first two dimensions of the input, preserving the other dimensions:

Apply the layer to an input:

Create a FlattenLayer that flattens the first three dimensions of its input together, and apply it to a 2×3×4×5 array:

Create and apply a FlattenLayer that flattens the last three dimensions together:

Create and apply a layer that flattens all the dimensions together:

Create a FlattenLayer that flattens levels 2 and 3 into the first level of the resulting array:

Create a FlattenLayer with specified input dimensions:

Thread the layer across a batch of inputs:

Properties & Relations  (4)

FlattenLayer[] behaves like Flatten:

FlattenLayer[n] computes:

Create a rank-3 array:

Flatten the first two dimensions:

Flatten the last two dimensions:

FlattenLayer[n] is equivalent to a ReshapeLayer[dims], where the dims depend on n and the dimensions of the input to FlattenLayer. Create a rank-3 array:

Apply a particular FlattenLayer:

Apply an equivalent ReshapeLayer:

In previous versions of the Wolfram Language, FlattenLayer was often used to convert a higher-rank array into a vector suitable for DotPlusLayer, the previous version of LinearLayer:

Unlike DotPlusLayer, LinearLayer can take arbitrary array inputs, and so the FlattenLayer is unnecessary:

Possible Issues  (3)

To prevent inadvertent errors, FlattenLayer[n] requires the input to have rank greater than n:

In contrast, Flatten[input,n] works for any n:

FlattenLayer[Infinity] accepts arrays of any rank:

If level transpositions are involved, FlattenLayer may not be able to process arrays with ranks higher than 5:

The computation can be performed if the number of transpositions needed is small enough:

FlattenLayer cannot accept symbolic inputs:

Wolfram Research (2016), FlattenLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/FlattenLayer.html (updated 2021).

Text

Wolfram Research (2016), FlattenLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/FlattenLayer.html (updated 2021).

CMS

Wolfram Language. 2016. "FlattenLayer." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/FlattenLayer.html.

APA

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

BibTeX

@misc{reference.wolfram_2023_flattenlayer, author="Wolfram Research", title="{FlattenLayer}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/FlattenLayer.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_flattenlayer, organization={Wolfram Research}, title={FlattenLayer}, year={2021}, url={https://reference.wolfram.com/language/ref/FlattenLayer.html}, note=[Accessed: 19-March-2024 ]}