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

Method transpose

xarray/core/dataset.py:6246–6300  ·  view source on GitHub ↗

Return a new Dataset object with all array dimensions transposed. Although the order of dimensions on each array will change, the dataset dimensions themselves will remain in fixed (sorted) order. Parameters ---------- *dim : hashable, optional B

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

Source from the content-addressed store, hash-verified

6244
6245 @deprecate_dims
6246 def transpose(
6247 self,
6248 *dim: Hashable,
6249 missing_dims: ErrorOptionsWithWarn = "raise",
6250 ) -> Self:
6251 """Return a new Dataset object with all array dimensions transposed.
6252
6253 Although the order of dimensions on each array will change, the dataset
6254 dimensions themselves will remain in fixed (sorted) order.
6255
6256 Parameters
6257 ----------
6258 *dim : hashable, optional
6259 By default, reverse the dimensions on each array. Otherwise,
6260 reorder the dimensions to this order.
6261 missing_dims : {"raise", "warn", "ignore"}, default: "raise"
6262 What to do if dimensions that should be selected from are not present in the
6263 Dataset:
6264 - "raise": raise an exception
6265 - "warn": raise a warning, and ignore the missing dimensions
6266 - "ignore": ignore the missing dimensions
6267
6268 Returns
6269 -------
6270 transposed : Dataset
6271 Each array in the dataset (including) coordinates will be
6272 transposed to the given order.
6273
6274 Notes
6275 -----
6276 This operation returns a view of each array's data. It is
6277 lazy for dask-backed DataArrays but not for numpy-backed DataArrays
6278 -- the data will be fully loaded into memory.
6279
6280 See Also
6281 --------
6282 numpy.transpose
6283 DataArray.transpose
6284 """
6285 # Raise error if list is passed as dim
6286 if (len(dim) > 0) and (isinstance(dim[0], list)):
6287 list_fix = [f"{x!r}" if isinstance(x, str) else f"{x}" for x in dim[0]]
6288 raise TypeError(
6289 f"transpose requires dim to be passed as multiple arguments. Expected `{', '.join(list_fix)}`. Received `{dim[0]}` instead"
6290 )
6291
6292 # Use infix_dims to check once for missing dimensions
6293 if len(dim) != 0:
6294 _ = list(infix_dims(dim, self.dims, missing_dims))
6295
6296 ds = self.copy()
6297 for name, var in self._variables.items():
6298 var_dims = tuple(d for d in dim if d in (var.dims + (...,)))
6299 ds._variables[name] = var.transpose(*var_dims)
6300 return ds
6301
6302 def dropna(
6303 self,

Callers 15

test_transpose_errorFunction · 0.95
streamplotFunction · 0.45
_infer_line_dataFunction · 0.45
_prepare_plot1d_dataFunction · 0.45
newplotfuncFunction · 0.45
permute_dimsFunction · 0.45
joinMethod · 0.45

Calls 4

copyMethod · 0.95
infix_dimsFunction · 0.90
itemsMethod · 0.80
joinMethod · 0.45