Skip to content

Is there a better way to set index as a "permanent" dim rather than a MultiIndex dim? #4800

Answered by keewis
ahuang11 asked this question in Q&A
Discussion options

You must be logged in to vote

not sure if there's a better way to do this, but you can combine the expressions and use da.sizes["index"] instead of len(da["index"]):

da = (
    da.stack({"index": ("lat", "lon")})
    .dropna("index")
    .reset_index("index")
    .assign_coords({"index": lambda x: np.arange(x.sizes["index"])})
)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ahuang11
Comment options

Answer selected by ahuang11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants