choose#
- ivy.choose(arr, choices, /, *, out=None, mode=None)[source]#
Take values from the input array by matching 1d index and data slices.
- Parameters:
arr (
Union
[Array
,NativeArray
]) – The source array.choices (
Union
[Array
,NativeArray
]) – The indices of the values to extract.out (
None
, default:None
) – The output array.mode (
Optional
[str
], default:None
) – One of: ‘wrap’, ‘clip’. Parameter controlling how out-of-bounds indices will be handled.
- Return type:
- Returns:
ret – The returned array has the same shape as indices.
Examples
>>> choices = ivy.array([[0, 1, 2, 3], [10, 11, 12, 13], ... [20, 21, 22, 23],[30, 31, 32, 33]]) >>> print(ivy.choose(choices, ivy.array([2, 3, 1, 0])) ivy.array([20, 31, 12, 3]) >>> arr = ivy.array([2, 4, 1, 0]) >>> print(ivy.choose(choices, arr, mode='clip')) # 4 goes to 3 (4-1) ivy.array([20, 31, 12, 3]) >>> arr = ivy.array([2, 4, 1, 0]) >>> print(ivy.choose(choices, arr, mode='wrap')) # 4 goes to (4 mod 4) ivy.array([20, 1, 12, 3])