Skip to content

Commit f74c446

Browse files
authored
DOC: add example for reindex (#4956)
* DOC: add example for reindex * rm white space * use arange
1 parent 835a53e commit f74c446

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

xarray/core/dataarray.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,26 @@ def reindex(
14981498
Another dataset array, with this array's data but replaced
14991499
coordinates.
15001500
1501+
Examples
1502+
--------
1503+
Reverse latitude:
1504+
1505+
>>> da = xr.DataArray(
1506+
... np.arange(4),
1507+
... coords=[np.array([90, 89, 88, 87])],
1508+
... dims="lat",
1509+
... )
1510+
>>> da
1511+
<xarray.DataArray (lat: 4)>
1512+
array([0, 1, 2, 3])
1513+
Coordinates:
1514+
* lat (lat) int64 90 89 88 87
1515+
>>> da.reindex(lat=da.lat[::-1])
1516+
<xarray.DataArray (lat: 4)>
1517+
array([3, 2, 1, 0])
1518+
Coordinates:
1519+
* lat (lat) int64 87 88 89 90
1520+
15011521
See Also
15021522
--------
15031523
DataArray.reindex_like

0 commit comments

Comments
 (0)