Value error in multiplying xarray variable with 2D numpy array

被刻印的时光 ゝ 提交于 2019-12-12 03:34:02

问题


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?


回答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)



回答2:


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



来源:https://stackoverflow.com/questions/35592074/value-error-in-multiplying-xarray-variable-with-2d-numpy-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!