'How to put a numpy array at a single location of a xarray dataset?

I have this xarray dataset:

<xarray.Dataset>
Dimensions:           (simName: 1, airport: 1, profnum: 193, level: 3, isEvening: 2)
Coordinates:
  * simName           (simName) <U35 'windhoek_0809_nofilter_v40_withAvgk'
  * airport           (airport) <U8 'Windhoek'
  * profnum           (profnum) int64 0 1 2 3 4 5 6 ... 187 188 189 190 191 192
  * level             (level) int64 0 1 2
    time              (simName, airport, profnum, level, isEvening) datetime64[ns] ...
Data variables:
    avgk              (simName, airport, profnum) float64 nan nan ... nan nan
    iasi              (simName, airport, profnum, level, isEvening) float64 0.3239 ... 0...

In the avgk variable, I want each location (simName, airport, profnum) to store a 43*43 numpy matrix. I want to be able to do an average on the lines of all avgk matrices (but I could do it with a loop). Is it possible ?

I tried to add the range(43) as coordinates but then it's messy with the subsequent slicing that I do with the time dimensions.

ValueError: coordinate ak_levels1 has dimensions ('ak_levels1',), but these are not a subset of the DataArray dimensions ('variable', 'simName', 'airport', 'profnum', 'level', 'isEvening')


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source