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

Method to_stacked_array

xarray/core/dataset.py:5330–5451  ·  view source on GitHub ↗

Combine variables of differing dimensionality into a DataArray without broadcasting. This method is similar to Dataset.to_dataarray but does not broadcast the variables. Parameters ---------- new_dim : hashable Name of the new stacked coo

(
        self,
        new_dim: Hashable,
        sample_dims: Collection[Hashable],
        variable_dim: Hashable = "variable",
        name: Hashable | None = None,
    )

Source from the content-addressed store, hash-verified

5328 return result
5329
5330 def to_stacked_array(
5331 self,
5332 new_dim: Hashable,
5333 sample_dims: Collection[Hashable],
5334 variable_dim: Hashable = "variable",
5335 name: Hashable | None = None,
5336 ) -> DataArray:
5337 """Combine variables of differing dimensionality into a DataArray
5338 without broadcasting.
5339
5340 This method is similar to Dataset.to_dataarray but does not broadcast the
5341 variables.
5342
5343 Parameters
5344 ----------
5345 new_dim : hashable
5346 Name of the new stacked coordinate
5347 sample_dims : Collection of hashables
5348 List of dimensions that **will not** be stacked. Each array in the
5349 dataset must share these dimensions. For machine learning
5350 applications, these define the dimensions over which samples are
5351 drawn.
5352 variable_dim : hashable, default: "variable"
5353 Name of the level in the stacked coordinate which corresponds to
5354 the variables.
5355 name : hashable, optional
5356 Name of the new data array.
5357
5358 Returns
5359 -------
5360 stacked : DataArray
5361 DataArray with the specified dimensions and data variables
5362 stacked together. The stacked coordinate is named ``new_dim``
5363 and represented by a MultiIndex object with a level containing the
5364 data variable names. The name of this level is controlled using
5365 the ``variable_dim`` argument.
5366
5367 See Also
5368 --------
5369 Dataset.to_dataarray
5370 Dataset.stack
5371 DataArray.to_unstacked_dataset
5372
5373 Examples
5374 --------
5375 >>> data = xr.Dataset(
5376 ... data_vars={
5377 ... "a": (("x", "y"), [[0, 1, 2], [3, 4, 5]]),
5378 ... "b": ("x", [6, 7]),
5379 ... },
5380 ... coords={"y": ["u", "v", "w"]},
5381 ... )
5382
5383 >>> data
5384 <xarray.Dataset> Size: 76B
5385 Dimensions: (x: 2, y: 3)
5386 Coordinates:
5387 * y (y) <U1 12B 'u' 'v' 'w'

Calls 3

concatFunction · 0.90
itemsMethod · 0.80
valuesMethod · 0.45