擅长:python、mysql、java
<h2>使用列表理解</h2>
<pre><code>choices = [['apple', 'orange'], ['strawberry', 'orange'], ['watermelon', 'apple']]
decisions = [0, 1, 0]
daily_decisions = [day[decision] for day, decision in zip(choices, decision)]
print(daily_decisions)
</code></pre>
<blockquote>
<p>['apple', 'orange', 'watermelon']</p>
</blockquote>
<h2>使用numpy</h2>
<p>这也可以用<a href="https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html#integer-array-indexing" rel="nofollow noreferrer">NumPys Integer Array Indexing</a>来解决:</p>
<pre><code>import numpy as np
daily_choices = np.array([['apple','orange'],['strawberry','orange'],['watermelon','apple']])
decisions = [0, 1, 0]
daily_decision = daily_choices[range(len(daily_choices)), decisions]
print(daily_decision)
</code></pre>
<blockquote>
<p>['apple', 'orange', 'watermelon']</p>
</blockquote>