Home > OS >  How to Turn a 3-D XArray Dataset into a 1D Dataset
How to Turn a 3-D XArray Dataset into a 1D Dataset

Time:08-19

I need to turn a 3-dimensional xarray DataArray into a 1-dimension dataset/dataarray in order to create a cumulative distribution function. I attempted to use dataset in question

Thank you for the help!

CodePudding user response:

You can stack the dimensions of an xarray.DataArray with xarray.DataArray.stack. Passing an ellipsis (...) in a list as the dimensions argument will stack all dimensions to create a 1-D array:

stacked = da.stack(stacked=[...])

if at this point you'd like a numpy 1-D array containing all values, you can access the .values attribute

stacked_values = stacked.values
  • Related