问题
As per Value error in multplying xarray variable with 2D numpy array
import xarray as xr
hndl_tran = xr.open_dataset(path_netcdf, chunks={'time': 10})
flow_data = hndl_tran['val']
new_arr = flow_data * xr.DataArray(vba)
Here are the shapes of input arrays
flow_data.shape
(1165, 720, 1440)
vba.shape
(720L, 1440L)
Here is the shape of the array after multiplying:
new_arr.shape
(1165, 720, 1440, 720, 1440)
I want the resulting array to have same shape as flow_data. How do i do this?
回答1:
xarray aligns the shapes based on the dimensions of the array. So if the dimensions don't share names, the multiplication is going to create a union of all dimensions.
I imagine flow_data
and vba
have differently named dimensions - use .rename
to set matching dimensions to matching names
来源:https://stackoverflow.com/questions/35593005/incorrect-shape-of-array-after-xarray-multiplication-operation