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

Method transpose

xarray/core/dataarray.py:3129–3177  ·  view source on GitHub ↗

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",
    )

Source from the content-addressed store, hash-verified

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:

Callers 7

TMethod · 0.95
test_interpolate_ndFunction · 0.95
test_multiple_groupersFunction · 0.95
test_math_with_coordsMethod · 0.95
test_transposeMethod · 0.95

Calls 3

_replaceMethod · 0.95
infix_dimsFunction · 0.90
itemsMethod · 0.80

Tested by 6

test_interpolate_ndFunction · 0.76
test_multiple_groupersFunction · 0.76
test_math_with_coordsMethod · 0.76
test_transposeMethod · 0.76