bundles / numpy 2.4.3 / numpy / ma / core / choose
function
numpy.ma.core:choose
source: /numpy/ma/core.py :8005
Signature
def choose ( indices , choices , out = None , mode = raise ) Summary
Use an index array to construct a new array from a list of choices.
Extended Summary
Given an array of integers and a list of n choice arrays, this method will create a new array that merges each of the choice arrays. Where a value in index is i, the new array will have the value that choices[i] contains in the same place.
Parameters
indices: ndarray of intsThis array must contain integers in
[0, n-1], where n is the number of choices.choices: sequence of arraysChoice arrays. The index array and all of the choices should be broadcastable to the same shape.
out: array, optionalIf provided, the result will be inserted into this array. It should be of the appropriate shape and dtype.
mode: {'raise', 'wrap', 'clip'}, optionalSpecifies how out-of-bounds indices will behave.
'raise'raise an error
'wrap'wrap around
'clip'clip to the range
Returns
merged_array: array
Examples
import numpy as np choice = np.array([[1,1,1], [2,2,2], [3,3,3]]) a = np.array([2, 1, 0]) np.ma.choose(a, choice)
See also
- choose
equivalent function
Aliases
-
numpy.ma.choose