Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To remove the zeros from an xarray DataArray called da, you can use the where method to create a new array with only the non-zero values:

da_nonzero = da.where(da != 0)

This creates a new DataArray da_nonzero that only contains the non-zero values of da. If you want to modify the original array da in place, you can assign the result back to da:

da = da.where(da != 0)