collapse

Contents

collapse#

class brainunit.lax.collapse(x, start_dimension, stop_dimension=None, unit_to_scale=None, **kwargs)#

Collapses dimensions of an array into a single dimension.

For example, if operand is an array with shape [2, 3, 4], collapse(operand, 0, 2).shape == [6, 4]. The elements of the collapsed dimension are laid out major-to-minor, i.e., with the lowest-numbered dimension as the slowest varying dimension.

Since collapsing is a pure reshape, the unit of a Quantity input is preserved by default.

Parameters:
  • x (Union[saiunit.Quantity, Array, ndarray, number, bool]) – an input array or Quantity.

  • start_dimension (int) – the start of the dimensions to collapse (inclusive).

  • stop_dimension (Optional[int]) – the end of the dimensions to collapse (exclusive). Pass None to collapse all the dimensions after start.

  • unit_to_scale (Optional[saiunit.Unit]) – if provided, a Quantity input is converted to this unit and the result is returned as a plain array (legacy behavior). If None, the unit of x is preserved.

Return type:

Union[saiunit.Quantity, Array]

Returns:

An array (or Quantity with the unit of x) where dimensions [start_dimension, stop_dimension) have been collapsed (raveled) into a single dimension.