Calling DataArrays inside of a Dataset with a variable

I have a Dataset structure that contains DataArrays as much as the number of the experiments that I am running. So for example, Dataset has 2 DataArrays named 'dataarray0' and 'dataarray1' when there is 2 experiments. I mostly add this DataArrays together to have better statistics but I don't want to do this manually as the number of experiments changes every time and I want to write a loop for that. How I can call a DataArray inside of a Dataset as a variable? Something similar to this:

datasetsum=dataset.dataarray1
n='number of experiments'
for i in range n:
    datasetsum=dataset.("dataarray%d" % i)
    return datasetsum
```


Read more here: https://stackoverflow.com/questions/65013089/calling-dataarrays-inside-of-a-dataset-with-a-variable

Content Attribution

This content was originally published by rctus at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: