This is an archival dump of old wiki content --- see scipy.org for current material

Abstract

Note: See [#Examples] for better clarity.

A selector array is used to map a tuple of other arrays (choices) which will be then be merged into the array being returned. selector must be broadcastable to the same shape as of the choices. The selector array's elements are merely the indices of the tuple that contains the choice arrays.

Signature


Function

choose(selector, choices, out=None, mode='raise')

Method

selector.choose(b0, b1, ..., bn, out=None, mode='raise')


Arguments

return
The merged array.
selector
Contains the desired indices of the tuple that houses the choice arrays.
out
Optional argument. The resulting array will be inserted into this array. It should naturally be of the same shape and dtype.
mode

{'raise','wrap','clip'} Specifies how out-of-bounds indices will behave.

raise
raise an error.
wrap
wrap around.
clip
clip to the range.

Details

xxx

Examples

   1 >>> from numpy import *
   2 >>> choice0 =array([10,12,14,16])                   # selector and choice arrays must be equally sized
   3 >>> choice1 =array([20,22,24,26])
   4 >>> choice2 =array([30,32,34,36])
   5 >>> selector = array([0,0,2,1])                     # selector can only contain integers in range(number_of_choice_arrays)
   6 >>> selector.choose(choice0,choice1,choice2)
   7 array([10, 12, 34, 26])
   8 >>> a = arange(4)
   9 >>> choose(a >= 2, (choice0, choice1))              # separate function also exists
  10 array([10, 12, 24, 26])

Notes

xxx

See Also

xxx

SciPy: choose (last edited 2015-10-24 17:48:26 by anonymous)