Previous topic

Next topic, choices, out=None, mode='raise')[source]

Use an index array to construct a new array from a set of choices.

Given an array of integers and a set of n choice arrays, this method will create a new array that merges each of the choice arrays. Where a value in a is i, the new array will have the value that choices[i] contains in the same place.

andarray of ints

This array must contain integers in [0, n-1], where n is the number of choices.

choicessequence of arrays

Choice arrays. The index array and all of the choices should be broadcastable to the same shape.

outarray, optional

If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype.

mode{‘raise’, ‘wrap’, ‘clip’}, optional

Specifies how out-of-bounds indices will behave.

  • ‘raise’ : raise an error

  • ‘wrap’ : wrap around

  • ‘clip’ : clip to the range


See also


equivalent function


>>> choice = np.array([[1,1,1], [2,2,2], [3,3,3]])
>>> a = np.array([2, 1, 0])
>>>, choice)
masked_array(data=[3, 2, 1],