0
import xarray as xr
xr.open_dataset(path_netcdf, chunks={'time': 10})
flow_data = hndl_tran['val']
new_arr = flow_data * vba

I get this error:

*** ValueError: total size of new array must be unchanged

Here are the shapes of the 2 arrays:

flow_data.shape
(1165, 720, 1440)

vba.shape
(720L, 1440L)

How can I fix this error?

2 Answers 2

1

Make your numpy into an xarray object before you do the multiplication:

flow_data = xr.DataArray(hndl_tran['val'])

or vice versa

flow_data = np.array(flow_data)
Sign up to request clarification or add additional context in comments.

3 Comments

please have a look at a corollary: stackoverflow.com/questions/35593005/…
hmm no idea what's causing this, can you try it the other way around, converting the xarray to numpy array?
that wouldn't work, if i try to convert the xarray to numpy array, the resulting numpy array is too big to fit in memory. thanks for looking :)
1

Building on @maxymoo's answer, you want to convert to a DataArray, but also supply dims, so operations with other arrays will work flow_data = xr.DataArray(hndl_tran['val'], dims=['date', 'id']), replacing date & id with the appropriate names

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.