[英]Dropping dimension without coordinate using xarray
<xarray.DataArray 'nc_file' (time: 20, latitude: 360, longitude: 720, N: 3)>
[34992000 values with dtype=float64]
Coordinates:
* latitude (latitude) float64 89.75 89.25 88.75 88.25 87.75 87.25 86.75 ...
* longitude (longitude) float64 -179.8 -179.2 -178.8 -178.2 -177.8 -177.2 ...
* time (time) float64 0.0 1.826e+03 3.652e+03 5.479e+03 7.305e+03 ...
Dimensions without coordinates: N
Attributes:
units: 1
long_name: sample data var
How do I drop N
from the netCDF using xarray?如何使用 xarray 从 netCDF 中删除N
? the xarray drop
command does not work xarray drop
命令不起作用
Assuming hndl_nc is the handle to the netCDF file, I tried hndl_nc.drop('N')
假设 hndl_nc 是 netCDF 文件的句柄,我尝试hndl_nc.drop('N')
not clear what you want to do: dataarr.drop('N') will remove only coordinate ;不清楚你想做什么: dataarr.drop('N') 将只删除坐标; mostly useful for redundant coordinate.主要用于冗余坐标。
but your data's equivalent numpy dimensions would still be array of shape (20,360,720,3) so you will always have N但是您的数据的等效 numpy 维度仍然是形状数组 (20,360,720,3),因此您将始终拥有 N
now you have to decide what you want to do with the last dimension N. had you selected N=1 or sum or some reduction operation on dimension N;现在您必须决定要对最后一个维度 N 做什么。您是否选择了 N=1 或求和或对维度 N 进行一些归约操作; then drop('N') will work.然后 drop('N') 将起作用。
If N just repeating same dataset of (time: 20, latitude: 360, longitude: 720) three times, then you can use hndl_nc.isel(N=0)
to drop the dimension, N.如果 N 只是重复(时间:20,纬度:360,经度:720)的相同数据集 3 次,那么您可以使用hndl_nc.isel(N=0)
删除维度 N。
If N gave you different dataset of (time: 20, latitude: 360, longitude: 720), you can keep the data by hndl_nc.squeeze('N')
, but noted that the structure of the data will be changed.如果 N 给你不同的数据集(时间:20,纬度:360,经度:720),你可以通过hndl_nc.squeeze('N')
保留数据,但注意数据的结构会改变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.