xarray乘法运算后数组的形状不正确 [英] Incorrect shape of array after xarray multiplication operation

查看:132
本文介绍了xarray乘法运算后数组的形状不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照将xarray变量与二维numpy数组

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)

这是输入数组的形状

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)

我希望所得数组具有与flow_data相同的形状.我该怎么做?

I want the resulting array to have same shape as flow_data. How do i do this?

推荐答案

xarray根据数组的尺寸对齐形状.因此,如果维度不共享名称,则乘法将创建所有维度的并集.

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.

我想flow_datavba具有不同的命名尺寸-使用.rename将匹配的尺寸设置为匹配的名称

I imagine flow_data and vba have differently named dimensions - use .rename to set matching dimensions to matching names

这篇关于xarray乘法运算后数组的形状不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆