numpy.choose()
numpy.choose
-
numpy.choose(a, choices, out=None, mode='raise')
[source] -
Construct an array from an index array and a set of arrays to choose from.
First of all, if confused or uncertain, definitely look at the Examples - in its full generality, this function is less simple than it might seem from the following code description (below ndi =
numpy.lib.index_tricks
):np.choose(a,c) == np.array([c[a[I]][I] for I in ndi.ndindex(a.shape)])
.But this omits some subtleties. Here is a fully general summary:
Given an “index” array (
a
) of integers and a sequence ofn
arrays (choices
),a
and each choice a