MCPcopy Index your code
hub / github.com/numpy/numpy / choose

Function choose

numpy/ma/core.py:8022–8095  ·  view source on GitHub ↗

Use an index array to construct a new array from a list of choices. 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]

(indices, choices, out=None, mode='raise')

Source from the content-addressed store, hash-verified

8020
8021
8022def choose(indices, choices, out=None, mode='raise'):
8023 """
8024 Use an index array to construct a new array from a list of choices.
8025
8026 Given an array of integers and a list of n choice arrays, this method
8027 will create a new array that merges each of the choice arrays. Where a
8028 value in `index` is i, the new array will have the value that choices[i]
8029 contains in the same place.
8030
8031 Parameters
8032 ----------
8033 indices : ndarray of ints
8034 This array must contain integers in ``[0, n-1]``, where n is the
8035 number of choices.
8036 choices : sequence of arrays
8037 Choice arrays. The index array and all of the choices should be
8038 broadcastable to the same shape.
8039 out : array, optional
8040 If provided, the result will be inserted into this array. It should
8041 be of the appropriate shape and `dtype`.
8042 mode : {'raise', 'wrap', 'clip'}, optional
8043 Specifies how out-of-bounds indices will behave.
8044
8045 * 'raise' : raise an error
8046 * 'wrap' : wrap around
8047 * 'clip' : clip to the range
8048
8049 Returns
8050 -------
8051 merged_array : array
8052
8053 See Also
8054 --------
8055 choose : equivalent function
8056
8057 Examples
8058 --------
8059 >>> import numpy as np
8060 >>> choice = np.array([[1,1,1], [2,2,2], [3,3,3]])
8061 >>> a = np.array([2, 1, 0])
8062 >>> np.ma.choose(a, choice)
8063 masked_array(data=[3, 2, 1],
8064 mask=False,
8065 fill_value=999999)
8066
8067 """
8068 def fmask(x):
8069 "Returns the filled array, or True if masked."
8070 if x is masked:
8071 return True
8072 return filled(x)
8073
8074 def nmask(x):
8075 "Returns the mask, True if ``masked``, False if ``nomask``."
8076 if x is masked:
8077 return True
8078 return getmask(x)
8079 # Get the indices.

Callers 3

test_testOddFeaturesMethod · 0.90
test_chooseMethod · 0.90
test_choose_with_outMethod · 0.90

Calls 8

filledFunction · 0.85
nmaskFunction · 0.85
fmaskFunction · 0.85
make_maskFunction · 0.85
mask_orFunction · 0.85
getmaskFunction · 0.85
__setmask__Method · 0.80
viewMethod · 0.45

Tested by 3

test_testOddFeaturesMethod · 0.72
test_chooseMethod · 0.72
test_choose_with_outMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…