[英]Reshaping 3D DataArray into 2d DataArray
I have xarray dataarray
of the following shape.我有以下形状的xarray dataarray
。
(10, 666, 999)
as ("band", "y", "x")
. (10, 666, 999)
作为("band", "y", "x")
。
I want to get new dataarray
into (666*999, 10)
shape.我想让新的数据dataarray
变成(666*999, 10)
形状。 How can I solve it?我该如何解决?
I tried as ans = x_arr.transpose("y", "x", "band").reshape(666*999, 10)
我试过ans = x_arr.transpose("y", "x", "band").reshape(666*999, 10)
but it did not work.但它没有用。 AttributeError: 'DataArray' object has no attribute 'reshape'
reference, http://xarray.pydata.org/en/stable/generated/xarray.DataArray.html参考, http://xarray.pydata.org/en/stable/generated/xarray.DataArray.html
You can use stack
to combine existing dimensions into a new one.您可以使用stack
将现有维度合并为一个新维度。 In your case it'd be something like darr.stack(xy=["x", "y"])
在你的情况下,它会像darr.stack(xy=["x", "y"])
Here's a reproducible example:这是一个可重现的示例:
x = xr.tutorial.load_dataset("air_temperature")
print(x.air.shape)
#(2920, 25, 53)
x2 = x.air.stack(point=["lat", "lon"])
print(x2.shape)
#(2920, 1325)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.