Incorrect shape of array after xarray multiplication operation

空扰寡人 提交于 2019-12-24 21:35:32

问题


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

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