represents a layer that aggregates an array of arbitrary rank into a vector, using the function f.


aggregates an array at level n.


aggregates an array at levels n1 through n2.


aggregates an array at levels n1,n2,.

Details and Options

  • AggregationLayer[f] operates on an array of dimensions {d1,,dn} to produce a vector of size d1, effectively mapping the function f over a list of flattened subarrays of size d2××dn.
  • AggregationLayer[f,{n1,,nk}] operates on a rank-m array of dimensions {d1,,dm} to produce an array of rank m-k, with dimensions Complement[{d1,,dm},{dn1,,dnk}].
  • Possible values for f are Mean, Min, Max, Total and Times.
  • AggregationLayer[f] is equivalent to AggregationLayer[f,2;;All].
  • AggregationLayer[][input] explicitly computes the output from applying the layer.
  • AggregationLayer[][{input1,input2,}] explicitly computes outputs for each of the inputi.
  • When given a NumericArray as input, the output will be a NumericArray.
  • AggregationLayer is typically used inside NetChain, NetGraph, etc. as the final stage in a chain of convolutions, poolings, etc. to convert an array with spatial dimensions into a fixed-size vector representation.
  • AggregationLayer can operate on arrays that contain "Varying" dimensions.
  • AggregationLayer exposes the following ports for use in NetGraph etc.:
  • "Input"an array
    "Output"an array
  • When it cannot be inferred from other layers in a larger net, the option "Input"{d1,,dn} can be used to fix the input of AggregationLayer to be an array of dimensions {d1,,dn}.


open all close all

Basic Examples  (2)

Create an AggregationLayer using Max as the aggregation function:

Click for copyable input

Create an AggregationLayer that sums the elements of each column of a matrix:

Click for copyable input

Apply the layer to an input:

Click for copyable input

Scope  (5)

Properties & Relations  (1)

Possible Issues  (1)

Introduced in 2017
Updated in 2018