[英]how do I remove unwanted empty dimension from xarray DataArray (squeeze doesn't work)
I have a DataArray that has four dimension, as you can see time has a size of 0: 我有一个具有四个维度的DataArray,如您所见,时间的大小为0:
<xarray.DataArray (color: 3, time: 0, y: 297, x: 496)>
array([], shape=(3, 0, 297, 496), dtype=float64)
Coordinates:
* y (y) float64 -3.199e+06 -3.199e+06 -3.199e+06 -3.199e+06 ...
* x (x) float64 1.966e+06 1.966e+06 1.966e+06 1.966e+06 1.966e+06 ...
* color (color) 'red' 'green' 'blue'
* time (time) datetime64[ns]
I need my DataArray to be in the format ('Y','X','color') however when I try to get rid of the time dimension using squeeze: 我需要DataArray的格式为('Y','X','color'),但是当我尝试使用挤压摆脱时间维度时:
new_darray = old_darray.squeeze('time')
this happens: 有时候是这样的:
IndexError: index 0 is out of bounds for axis 0 with size 0
and when I try this: 当我尝试这个:
new_darray = old_darray[:,0,:,:]
this happens too: 这也会发生:
IndexError: index 0 is out of bounds for axis 0 with size 0
You can't index or squeeze out a size 0 dimension, in either xarray or NumPy. 您不能在xarray或NumPy中索引或压缩大小为0的维。 That would entail transforming an empty array of size
3 * 0 * 279 * 496 = 0
into an array full of data of size 3 * 279 * 496 = 415152
. 这将需要将大小为
3 * 0 * 279 * 496 = 0
的空数组转换为充满大小为3 * 279 * 496 = 415152
数据的数组。 Where would the new data come from? 新数据从何而来?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.