Flatten

Flatten#

class brainpy.dnn.Flatten(start_dim=0, end_dim=-1, name=None, mode=None)[source]#

Flattens a contiguous range of dims into a tensor. For use with Sequential.

Shape:
  • Input: \((*, S_{\text{start}},..., S_{i}, ..., S_{\text{end}}, *)\),’ where \(S_{i}\) is the size at dimension \(i\) and \(*\) means any number of dimensions including none.

  • Output: \((*, \prod_{i=\text{start}}^{\text{end}} S_{i}, *)\).

Parameters:
  • start_dim (int) – first dim to flatten (default = 1).

  • end_dim (int) – last dim to flatten (default = -1).

  • name (Optional[str]) – str, Optional. The name of the object.

  • mode (Optional[Mode]) – Mode. Enable training this node or not. (default True).

Examples::
>>> import brainpy.math as bm
>>> inp = bm.random.randn(32, 1, 5, 5)
>>> # With default parameters
>>> m = Flatten()
>>> output = m(inp)
>>> output.shape
(32, 25)
>>> # With non-default parameters
>>> m = Flatten(0, 2)
>>> output = m(inp)
>>> output.shape
(160, 5)
update(x)[source]#

The function to specify the updating rule.