cf.FieldAncillary.flatten

FieldAncillary.flatten(*args, **kwargs)[source]

Flatten axes of the data.

Any subset of the axes may be flattened.

The shape of the data may change, but the size will not.

The flattening is executed in row-major (C-style) order. For example, the array [[1, 2], [3, 4]] would be flattened across both dimensions to [1 2 3 4].

New in version 3.0.2.

Parameters
axes: (sequence of) int or str, optional

Select the axes. By default all axes are flattened. The axes argument may be one, or a sequence, of:

  • An internal axis identifier. Selects this axis.

  • An integer. Selects the axis corresponding to the given position in the list of axes of the data array.

No axes are flattened if axes is an empty sequence.

inplace: bool, optional

If True then do the operation in-place and return None.

Returns
FieldAncillary or None

The construct with flattened data, or None if the operation was in-place.

Examples

>>> f.shape
(1, 2, 3, 4)
>>> f.flatten().shape
(24,)
>>> f.flatten([1, 3]).shape
(1, 8, 3)
>>> f.flatten([0, -1], inplace=True)
>>> f.shape
(4, 2, 3)