- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我需要向 DataArray
添加一个维度,填充新维度中的值。这是原始数组。
a_size = 10
a_coords = np.linspace(0, 1, a_size)
b_size = 5
b_coords = np.linspace(0, 1, b_size)
# original 1-dimensional array
x = xr.DataArray(
np.random.random(a_size),
coords=[('a', a coords)])
我想我可以创建一个具有新维度的空 DataArray 并将现有数据复制进去。
y = xr.DataArray(
np.empty((b_size, a_size),
coords=([('b', b_coords), ('a', a_coords)])
y[:] = x
一个更好的主意可能是使用concat
。我花了一段时间才弄清楚如何为 concat 维度指定 dims 和 coords,这些选项似乎都不是很好。有没有我遗漏的东西可以使这个版本更干净?
# specify the dimension name, then set the coordinates
y = xr.concat([x for _ in b_coords], 'b')
y['b'] = b_coords
# specify the coordinates, then rename the dimension
y = xr.concat([x for _ in b_coords], b_coords)
y.rename({'concat_dim': 'b'})
# use a DataArray as the concat dimension
y = xr.concat(
[x for _ in b_coords],
xr.DataArray(b_coords, name='b', dims=['b']))
不过,还有比上述两种选择更好的方法吗?
最佳答案
如果 DA
是长度为 DimLen
的数据数组,您现在可以使用 expand_dims
:
DA.expand_dims({'NewDim':DimLen})
关于python - 向 xarray DataArray 添加维度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39626402/
假设我有以下二维数组 >>> import numpy as np >>> budgets = np.array([ [np.nan, 450.], [500. , 10
我正在尝试读取单个 WRF 的时间序列输出变量。时间序列是分布式的,每个文件一个时间戳,跨越 5000 多个 netCDF 文件。每个文件包含大约 200 个变量。 有没有办法只为我感兴趣的变量调用
我有一个相当大的 xr.Dataset,其中包含大约 20 个数据变量。我只对保留其中两个感兴趣。我看到 xr.Dataset.drop带有数据集的删除变量。 我正在寻找保留变量的语法。我尝试了 f[
我正在尝试计算 xarray 数据集中时间维度子集的每月气候。时间是使用 datetime64 定义的。 如果我想使用整个时间序列,这很好用: monthly_avr=ds_clm.groupby('
我有一个空间数据的 pandas 数据框,我想将其转换为 netCDF。我找到了 xarray 并将我的数据帧转换为 xarray 数据集的方法: # create xray Dataset from
我有一个名为 rio 的 DataArray 对象。 In [59]: rio Out[59]: array([[[0, 0, ..., 0, 0], [0, 0, ..., 0,
我目前正在尝试将一个大的多维数组 (>5 GB) 加载到 python 脚本中。由于我将数组用作机器学习模型的训练数据,因此以小批量高效加载数据非常重要,但要避免将整个数据集加载到内存中一次。 我的想
假设我有一个 dataset类型 xarray.Dataset .我有一个名为 name 的维度,(由 DataArray 中的所有 Dataset 共享,但我认为这对这个问题并不重要,)我想选择一个
我想读入 https://hrrrzarr.s3.amazonaws.com/index.html#sfc/20210208/20210208_00z_anl.zarr/ 的远程 zarr 存储。 z
我想获取栅格(卫星图像)数据,并构建一个Dataset 或DataArray,以加快我的图像处理速度(我必须处理多-波段,多日期卫星图像很多)。 数据来自每个图像日期的单独波段,我了解如何将每个波段日
所以我有 3 个 netcdf4 文件(每个大约 90 MB),我想使用包 xarray 将它们连接起来。每个文件都有一个变量 (dis),以 0.5 度分辨率(纬度、经度)表示 365 天(时间)。
对于我的数据数组,我有坐标经度、纬度和时间。我只想沿纬度反转数组,以便 [90, 85, ..., -85, -90]变成 [-90, -80, ..., 85, 90] . 最佳答案 同意@jham
完成 MetPy 横截面示例后,我尝试将该示例推广到 NCEP NAM-12km GRIB2 文件,但未成功。通过将我的文件的 DataArray 与示例文件(netCDF 文件)进行比较,我发现 x
我正在使用 xarray.apply_ufunc() 将函数应用于 xarray.DataArray .它适用于某些 NetCDF,但在尺寸、坐标等方面似乎具有可比性的其他 NetCDF 会失败。但是
是否也可以创建一个核外 DataArray,并使用 xarray 将其逐块写入 NetCDF4 文件? 例如,当维度更大时,我希望能够以核外方式执行此操作,因此我无法将整个数组存储在内存中: num_
我有一个数据数组arr,坐标为“时间”。到达: array([244.40161, 244.39998, ..., 244.40936, 244.40549], dtype=float32)
我有一个数据数组arr,坐标为“时间”。到达: array([244.40161, 244.39998, ..., 244.40936, 244.40549], dtype=float32)
我是新手,我使用的是XARRAY。我的netcdf文件包含时间为‘天数自0001-01-01 00:00:00’的数据,日历类型为Julian。有谁知道将时间转换成标准日历的简单方法吗?。提前感谢:)
我是新手,我使用的是XARRAY。我的netcdf文件包含时间为‘天数自0001-01-01 00:00:00’的数据,日历类型为Julian。有谁知道将时间转换成标准日历的简单方法吗?。提前感谢:)
我是新手,我使用的是XARRAY。我的netcdf文件包含时间为‘天数自0001-01-01 00:00:00’的数据,日历类型为Julian。有谁知道将时间转换成标准日历的简单方法吗?。提前感谢:)
我是一名优秀的程序员,十分优秀!