cf.Field.transpose¶
-
Field.
transpose
(axes=None, i=False, **kwargs)[source]¶ Permute the axes of the data array.
By default the order of the axes is reversed, but any ordering may be specified by selecting the axes of the output in the required order.
The axes are selected with the axes parameter.
See also
Examples 1: Reverse the order of the axes:
>>> g = f.transpose()
Specify a particular axes order:
>>> g = f.transpose(['T', 'X', 'Y'])
See also
Parameters: - axes, kwargs : optional
Select axes. The axes parameter may be one, or a sequence, of:
None
. If no kwargs arguments have been set then all axes are selected. This is the default.
An integer. Explicitly selects the axis corresponding to the given position in the list of axes of the field’s data array.
- Example:
To select the third data array axis:
axes=2
. To select the last axis:axes=-1
.
A
slice
object. Explicitly selects the axes corresponding to the given positions in the list of axes of the field’s data array.- Example:
To select the last three data array axes:
axes=slice(-3, None)
A domain axis identifier. Explicitly selects this axis.
- Example:
To select axis “dim1”:
axes='dim1'
.
Any value accepted by the items parameter of the field’s
items
method. Used in conjunction with the kwargs parameters to select the axes which span the items that would be identified by this call of the field’sitems
method:f.items(items=axes, axes=None, **kwargs)
. Seecf.Field.items
for details.- Example:
To select the axes spanned by one dimensionsal time coordinates:
f.transpose('T', ndim=1)
.
If axes is a sequence of any combination of the above then the selected axes are the union of those selected by each element of the sequence. If the sequence is empty then no axes are selected.
- i : bool, optional
If True then update the field in place. By default a new field is created. In either case, a field is returned.
Returns: - out : cf.Field
, the transposed field.
Examples 2: >>> f.items() {'dim0': <CF DimensionCoordinate: time(12) noleap>, 'dim1': <CF DimensionCoordinate: latitude(64) degrees_north>, 'dim2': <CF DimensionCoordinate: longitude(128) degrees_east>, 'dim3': <CF DimensionCoordinate: height(1) m>} >>> f.data_axes() ['dim0', 'dim1', 'dim2'] >>> f.transpose() >>> f.transpose(['latitude', 'time', 'longitude']) >>> f.transpose([1, 0, 2]) >>> f.transpose((1, 'time', 'dim2'))