Skip to content

xarray.Dataset.from_array #5768

Answered by TomNicholas
raybellwaves asked this question in Ideas
Discussion options

You must be logged in to vote

Hi @raybellwaves, thanks for the suggestion.

Motivation here is a one-line inverse transform of ds.to_numpy().

I'm a bit confused though - this is already a one-line conversion? You could of course make it neater by locally defining

def numpy_array_to_ds(arr, name="arr"):
    return xr.DataArray(arr).to_dataset(name=name)

I suppose we could perhaps try to further generalise Dataset.__init__, although it is already quite a complicated constructor...

Motivation here is a one-line inverse transform of ds.to_numpy().

(FYI the original motivation for ds.to_numpy() was situations where you need to strip the array of any other duck-type wrappers, for instance pint units. I feel like that isn…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@raybellwaves
Comment options

@raybellwaves
Comment options

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