Return a new DataArray object with transposed dimensions. Parameters ---------- *dim : Hashable, optional By default, reverse the dimensions. Otherwise, reorder the dimensions to this order. transpose_coords : bool, default: True I
(
self,
*dim: Hashable,
transpose_coords: bool = True,
missing_dims: ErrorOptionsWithWarn = "raise",
)
| 3127 | |
| 3128 | @deprecate_dims |
| 3129 | def transpose( |
| 3130 | self, |
| 3131 | *dim: Hashable, |
| 3132 | transpose_coords: bool = True, |
| 3133 | missing_dims: ErrorOptionsWithWarn = "raise", |
| 3134 | ) -> Self: |
| 3135 | """Return a new DataArray object with transposed dimensions. |
| 3136 | |
| 3137 | Parameters |
| 3138 | ---------- |
| 3139 | *dim : Hashable, optional |
| 3140 | By default, reverse the dimensions. Otherwise, reorder the |
| 3141 | dimensions to this order. |
| 3142 | transpose_coords : bool, default: True |
| 3143 | If True, also transpose the coordinates of this DataArray. |
| 3144 | missing_dims : {"raise", "warn", "ignore"}, default: "raise" |
| 3145 | What to do if dimensions that should be selected from are not present in the |
| 3146 | DataArray: |
| 3147 | - "raise": raise an exception |
| 3148 | - "warn": raise a warning, and ignore the missing dimensions |
| 3149 | - "ignore": ignore the missing dimensions |
| 3150 | |
| 3151 | Returns |
| 3152 | ------- |
| 3153 | transposed : DataArray |
| 3154 | The returned DataArray's array is transposed. |
| 3155 | |
| 3156 | Notes |
| 3157 | ----- |
| 3158 | This operation returns a view of this array's data. It is |
| 3159 | lazy for dask-backed DataArrays but not for numpy-backed DataArrays |
| 3160 | -- the data will be fully loaded. |
| 3161 | |
| 3162 | See Also |
| 3163 | -------- |
| 3164 | numpy.transpose |
| 3165 | Dataset.transpose |
| 3166 | """ |
| 3167 | if dim: |
| 3168 | dim = tuple(infix_dims(dim, self.dims, missing_dims)) |
| 3169 | variable = self.variable.transpose(*dim) |
| 3170 | if transpose_coords: |
| 3171 | coords: dict[Hashable, Variable] = {} |
| 3172 | for name, coord in self.coords.items(): |
| 3173 | coord_dims = tuple(d for d in dim if d in coord.dims) |
| 3174 | coords[name] = coord.variable.transpose(*coord_dims) |
| 3175 | return self._replace(variable, coords) |
| 3176 | else: |
| 3177 | return self._replace(variable) |
| 3178 | |
| 3179 | @property |
| 3180 | def T(self) -> Self: |