xdas.DataArray.transpose#

DataArray.transpose(*dims)[source]#

Return a new DataArray object with transposed dimensions.

Parameters:

*dims (Hashable, optional) – By default, reverse the dimensions. Otherwise, reorder the dimensions to this order. The provided dims must be a permutation of the original dimensions. If is provided, it is replaced by the missing dimensions.

Returns:

transposed – The returned DataArray’s array is transposed.

Return type:

DataArray

Notes

This operation returns a view of this array’s data if this later is a numpy.ndarray object. Otherwise the data is loaded into memory.

See also

numpy.transpose

Examples

>>> import xdas as xd
>>> import numpy as np
>>> da = xd.DataArray(
...     np.arange(2 * 3).reshape(2, 3), {"x": [0, 1], "y": [2, 3, 4]}
... )
>>> da
<xdas.DataArray (x: 2, y: 3)>
[[0 1 2]
 [3 4 5]]
Coordinates:
  * x (x): [0 1]
  * y (y): [2 ... 4]
>>> da.transpose("y", "x")  # equivalent to not providing any arguments here
<xdas.DataArray (y: 3, x: 2)>
[[0 3]
 [1 4]
 [2 5]]
Coordinates:
  * x (x): [0 1]
  * y (y): [2 ... 4]
>>> assert da.transpose(..., "x").equals(da.transpose("y", ...))  # equivalent