Skip to content

Commit d8a4d41

Browse files
committed
Add two examples to choose
1 parent 2cd10b3 commit d8a4d41

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

dpnp/dpnp_iface_indexing.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,40 @@ def choose(a, choices, out=None, mode="wrap"):
227227
See also
228228
--------
229229
:obj:`dpnp.ndarray.choose` : Equivalent method.
230+
231+
Examples
232+
--------
233+
>>> import dpnp as np
234+
>>> choices = np.array[[0, 1, 2, 3], [10, 11, 12, 13],
235+
... [20, 21, 22, 23], [30, 31, 32, 33]])
236+
>>> np.choose(np.array([2, 3, 1, 0]), choices
237+
... # the first element of the result will be the first element of the
238+
... # third (2+1) "array" in choices, namely, 20; the second element
239+
... # will be the second element of the fourth (3+1) choice array, i.e.,
240+
... # 31, etc.
241+
... )
242+
array([20, 31, 12, 3])
243+
>>> np.choose(np.array([2, 4, 1, 0]), choices, mode='clip'
244+
... # 4 goes to 3 (4-1)
245+
... )
246+
array([20, 31, 12, 3])
247+
>>> # because there are 4 choice arrays
248+
>>> np.choose(np.array([2, 4, 1, 0]), choices, mode='wrap'
249+
... # 4 is clipped to 3
250+
... )
251+
array([20, 31, 12, 3])
252+
>>> np.choose(np.array([2, -1, 1, 0]), choices, mode='wrap'
253+
... # -1 goes to 3 (-1+4)
254+
... )
255+
array([20, 31, 12, 3])
256+
257+
An example using broadcasting:
258+
>>> a = np.array([[1, 0, 1], [0, 1, 0], [1, 0, 1]])
259+
>>> choices = np.array([-10, 10])
260+
>>> np.choose(a, choices)
261+
array([[ 10, -10, 10],
262+
[-10, 10, -10],
263+
[ 10, -10, 10]])
230264
"""
231265
mode = _get_indexing_mode(mode)
232266

0 commit comments

Comments
 (0)