I have a DataArray for which da.dims==()
. I can assign a coordinate da.assign_coords(foo=42)
. I would like to add a corresponding dimension with length one, such that da.dims==("foo",)
and the corresponding coordinate would be foo=[42]
. I cannot use assign_coords(foo=[42])
, as this results in the error message cannot add coordinates with new dimensions to a DataArray
.
How do I assign a new dimension of length one to a DataArray? I could do something like DataArray(da.values.reshape([1]), dims="foo", coords={"foo": [42]})
but I wonder if there is a method that does not require copying the entire object.