Ask Your Question
3

How do you remove the zeros from an xarray DataArray?

asked 2023-05-07 19:02:23 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-07 19:27:02 +0000

lalupa gravatar image

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)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-07 19:02:23 +0000

Seen: 15 times

Last updated: May 07 '23