[英]Value error in multiplying xarray variable with 2D numpy array
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: 这是2个数组的形状:
flow_data.shape
(1165, 720, 1440)
vba.shape
(720L, 1440L)
How can I fix this error? 如何解决此错误?
Make your numpy into an xarray
object before you do the multiplication: 在进行乘法之前,将numpy放入
xarray
对象中:
flow_data = xr.DataArray(hndl_tran['val'])
or vice versa 或相反亦然
flow_data = np.array(flow_data)
以@maxymoo的答案为基础,您希望转换为DataArray
, 但也要提供dims ,因此对其他数组的操作将可以正常工作flow_data = xr.DataArray(hndl_tran['val'], dims=['date', 'id'])
,用适当的名称替换日期和ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.