-
If we have some function At the moment I'm running a loop for each parameter, adding to a Dataset, and then folding each dimension into a DataArray, like: # Setup
import xarray as xr
def generate_timeseries(x, y):
return np.random.normal(loc=x, scale=y, size=100)
N = 100
xs = [x / N for x in range(N + 1)]
ys = [y / N for y in range(N + 1)]
# Xarray code
x_ds = xr.Dataset()
for x in xs:
y_ds = xr.Dataset()
for y in ys:
y_ds[y] = xr.DataArray(
data=generate_timeseries(x=x, y=y),
dims=["date"],
)
x_ds[x] = y_ds.to_array(dim="y")
da = x_ds.to_array("x")
da
Has anyone found a pattern for doing this even more simply, and possibly invariant to the number of dimensions? Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
dcherian
Feb 2, 2023
Replies: 1 comment 2 replies
-
Does xyzpy handle this case? https://xyzpy.readthedocs.io/en/latest/generate.html |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
max-sixty
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does xyzpy handle this case? https://xyzpy.readthedocs.io/en/latest/generate.html