xarray add coordinate

Solutions on MaxInterview for xarray add coordinate by the best coders in the world

showing results for - "xarray add coordinate"
Leni
31 Sep 2018
1>>> da = xr.DataArray(
2...     np.random.rand(4),
3...     coords=[np.array([358, 359, 0, 1])],
4...     dims="lon",
5... )
6>>> da
7<xarray.DataArray (lon: 4)>
8array([0.5488135 , 0.71518937, 0.60276338, 0.54488318])
9Coordinates:
10  * lon      (lon) int64 358 359 0 1
11  
12>>> da.assign_coords(lon=(((da.lon + 180) % 360) - 180))
13<xarray.DataArray (lon: 4)>
14array([0.5488135 , 0.71518937, 0.60276338, 0.54488318])
15Coordinates:
16  * lon      (lon) int64 -2 -1 0 1
17