Skip to content

A way to stack all dimensions but one? #8278

Closed
@carschandler

Description

@carschandler

Is your feature request related to a problem?

One thing I find useful with DataArrays is the ability to take all dimensions but one, stack them into one MultiIndex, and then iterate over the entries of that MultiIndex. For example, I have a DataArray that starts with a time dimension/coordinate. I then add several new dimensions/coords that correspond to varying input parameters (i.e. one for initial velocity, initial position, air density, etc.). What I then want to do is iterate over all 1D time vectors (all the combinations of those variable input parameters). The easiest way I've found to do this is to stack all the dimensions except time and then iterate over the resulting MultiIndex. I have been doing this by converting the dims of the DataArray to a list and then removing "time" from that list and using it as the input to stack.

Describe the solution you'd like

It would be awesome if there was a method that could specifically stack all dimensions except for a list of specified dimension names (something like DataArray.stack_except({"name_of_created_stacked_dimension": ["dim_to_leave_unstacked", "another_dim"])), or some kind of syntax that would allow an "all except" behavior to be passed directly into stack (could be something like `DataArray.stack({"name_of_created_stacked_dimension"}: ["dim_to_leave_unstacked"], invert=True).

Describe alternatives you've considered

If there is a better way to achieve what I'm trying to accomplish (take one dimension and iterate over all the combinations of the other dimensions, resulting in 1D vectors that vary along the single desired dimension), then I would welcome any tips!

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions