Return a new object with transposed dimensions. Parameters ---------- *dim : Hashable, optional By default, reverse the order of the dimensions. Otherwise, reorder the dimensions to this order. missing_dims : {"raise", "warn", "ignore"}, defau
(
self,
*dim: Iterable[_Dim] | EllipsisType,
missing_dims: ErrorOptionsWithWarn = "raise",
)
| 1003 | raise TypeError("self.data is not a sparse array") |
| 1004 | |
| 1005 | def permute_dims( |
| 1006 | self, |
| 1007 | *dim: Iterable[_Dim] | EllipsisType, |
| 1008 | missing_dims: ErrorOptionsWithWarn = "raise", |
| 1009 | ) -> NamedArray[Any, _DType_co]: |
| 1010 | """Return a new object with transposed dimensions. |
| 1011 | |
| 1012 | Parameters |
| 1013 | ---------- |
| 1014 | *dim : Hashable, optional |
| 1015 | By default, reverse the order of the dimensions. Otherwise, reorder the |
| 1016 | dimensions to this order. |
| 1017 | missing_dims : {"raise", "warn", "ignore"}, default: "raise" |
| 1018 | What to do if dimensions that should be selected from are not present in the |
| 1019 | NamedArray: |
| 1020 | - "raise": raise an exception |
| 1021 | - "warn": raise a warning, and ignore the missing dimensions |
| 1022 | - "ignore": ignore the missing dimensions |
| 1023 | |
| 1024 | Returns |
| 1025 | ------- |
| 1026 | NamedArray |
| 1027 | The returned NamedArray has permuted dimensions and data with the |
| 1028 | same attributes as the original. |
| 1029 | |
| 1030 | |
| 1031 | See Also |
| 1032 | -------- |
| 1033 | numpy.transpose |
| 1034 | """ |
| 1035 | |
| 1036 | from xarray.namedarray._array_api import permute_dims |
| 1037 | |
| 1038 | if not dim: |
| 1039 | dims = self.dims[::-1] |
| 1040 | else: |
| 1041 | dims = tuple(infix_dims(dim, self.dims, missing_dims)) # type: ignore[arg-type] |
| 1042 | |
| 1043 | if len(dims) < 2 or dims == self.dims: |
| 1044 | # no need to transpose if only one dimension |
| 1045 | # or dims are in same order |
| 1046 | return self.copy(deep=False) |
| 1047 | |
| 1048 | axes = self.get_axis_num(dims) |
| 1049 | assert isinstance(axes, tuple) |
| 1050 | |
| 1051 | return permute_dims(self, axes) |
| 1052 | |
| 1053 | @property |
| 1054 | def T(self) -> NamedArray[Any, _DType_co]: |