Skip to content

Commit

Permalink
flip
Browse files Browse the repository at this point in the history
  • Loading branch information
Illviljan committed Sep 30, 2024
1 parent 6499fb7 commit 4dba4bf
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions xarray/namedarray/_array_api/_manipulation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,28 @@ def expand_dims(
def flip(
x: NamedArray[_ShapeType, _DType], /, *, axis: _Axes | None = None
) -> NamedArray[_ShapeType, _DType]:
"""
Reverse the order of elements in an array along the given axis.
Examples
--------
>>> import numpy as np
>>> A = NamedArray(("x",), np.arange(8))
>>> flip(A, axis=0)
<xarray.NamedArray (x: 8)> Size: 64B
array([7, 6, 5, 4, 3, 2, 1, 0])
>>> A = NamedArray(("z", "y", "x"), np.arange(8).reshape((2, 2, 2)))
>>> flip(A, axis=0)
<xarray.NamedArray (z: 2, y: 2, x: 2)> Size: 64B
array([[[4, 5],
[6, 7]],
<BLANKLINE>
[[0, 1],
[2, 3]]])
"""
xp = _get_data_namespace(x)
_data = xp.flip(x._data, axis=axis)
_dims = _infer_dims(_data.shape) # TODO: Fix dims
return x._new(_dims, _data)
return x._new(x.dims, _data)


def moveaxis(
Expand Down

0 comments on commit 4dba4bf

Please sign in to comment.