user308827
user308827

Reputation: 21961

Incorrect shape of array after xarray multiplication operation

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?

Upvotes: 0

Views: 878

Answers (1)

Maximilian
Maximilian

Reputation: 8450

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

Upvotes: 2

Related Questions