MCPcopy
hub / github.com/pydata/xarray / transpose

Method transpose

xarray/core/variable.py:1394–1440  ·  view source on GitHub ↗

Return a new Variable object with transposed dimensions. Parameters ---------- *dim : Hashable, optional By default, reverse the dimensions. Otherwise, reorder the dimensions to this order. missing_dims : {"raise", "warn", "ignore"}, default:

(
        self,
        *dim: Hashable | EllipsisType,
        missing_dims: ErrorOptionsWithWarn = "raise",
    )

Source from the content-addressed store, hash-verified

1392
1393 @deprecate_dims
1394 def transpose(
1395 self,
1396 *dim: Hashable | EllipsisType,
1397 missing_dims: ErrorOptionsWithWarn = "raise",
1398 ) -> Self:
1399 """Return a new Variable object with transposed dimensions.
1400
1401 Parameters
1402 ----------
1403 *dim : Hashable, optional
1404 By default, reverse the dimensions. Otherwise, reorder the
1405 dimensions to this order.
1406 missing_dims : {"raise", "warn", "ignore"}, default: "raise"
1407 What to do if dimensions that should be selected from are not present in the
1408 Variable:
1409 - "raise": raise an exception
1410 - "warn": raise a warning, and ignore the missing dimensions
1411 - "ignore": ignore the missing dimensions
1412
1413 Returns
1414 -------
1415 transposed : Variable
1416 The returned object has transposed data and dimensions with the
1417 same attributes as the original.
1418
1419 Notes
1420 -----
1421 This operation returns a view of this variable's data. It is
1422 lazy for dask-backed Variables but not for numpy-backed Variables.
1423
1424 See Also
1425 --------
1426 numpy.transpose
1427 """
1428 if len(dim) == 0:
1429 dim = self.dims[::-1]
1430 else:
1431 dim = tuple(infix_dims(dim, self.dims, missing_dims))
1432
1433 if len(dim) < 2 or dim == self.dims:
1434 # no need to transpose if only one dimension
1435 # or dims are in same order
1436 return self.copy(deep=False)
1437
1438 axes = self.get_axis_num(dim)
1439 data = as_indexable(self._data).transpose(axes)
1440 return self._replace(dims=dim, data=data)
1441
1442 @property
1443 def T(self) -> Self:

Callers 10

TMethod · 0.95
set_dimsMethod · 0.95
_stack_onceMethod · 0.95
_unstack_once_fullMethod · 0.95
_unstack_onceMethod · 0.95
test_transposeMethod · 0.95
test_transpose_0dMethod · 0.95
quantileMethod · 0.45
rankMethod · 0.45

Calls 5

_replaceMethod · 0.95
infix_dimsFunction · 0.90
as_indexableFunction · 0.90
copyMethod · 0.45
get_axis_numMethod · 0.45

Tested by 3

test_transposeMethod · 0.76
test_transpose_0dMethod · 0.76