Alternative for numpy.choose that allows an arbitrary or at least more than 32 arguments?
<p>With my code I'm running into an issue where the <code>numpy.choose</code> methods does not accept all the arguments since it is limited by <code>NPY_MAXARGS</code> (<code>=32</code>). Is there an alternative available, that allows an arbitrary number of argument arrays or at least more than <code>32</code> that is as fast as <code>numpy.choose</code>?</p>

<pre><code>choices = [np.arange(0,100)]*100
selection = [0] * 100
np.choose(selection, choices)

&gt;&gt; ValueError: Need between 2 and (32) array objects (inclusive).
</code></pre>

<p>Any help would be appreciated... :)</p>

<p>The indices can be given as lists. Assuming that <code>selections</code> has the same length as <code>choices</code>:</p>

<pre><code>b = numpy.array(choices)
result = b[range(len(selections)), selections]
</code></pre>

<p>will give the value in choices specified by the index in selections. See it in action:</p>

<pre><code>numpy.random.seed(1)
b = numpy.random.randint(0,100,(5,10))
&gt;&gt;&gt; array([[37, 12, 72,  9, 75,  5, 79, 64, 16,  1],
          [76, 71,  6, 25, 50, 20, 18, 84, 11, 28],
          [29, 14, 50, 68, 87, 87, 94, 96, 86, 13],
          [ 9,  7, 63, 61, 22, 57,  1,  0, 60, 81],
          [ 8, 88, 13, 47, 72, 30, 71,  3, 70, 21]])

selections = numpy.random.randint(0,10,5)
&gt;&gt;&gt; array([1, 9, 3, 4, 8])

result = b[range(len(selections)),selections]
&gt;&gt;&gt;&gt; array([12, 28, 68, 22, 70])
</code></pre>

python numpy