擅长:python、mysql、java
<p>首先,要获取7的最后一个匹配项的索引,可以使用:</p>
<pre><code>import numpy as np
a = np.array([1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1])
indices = np.argwhere(a== 7)
last_index = indices[-1]
# 10
</code></pre>
<p>现在,如果您有一个三维数组,您仍然可以使用<code>np.argwhere</code>来获取7的引用,但是每个引用都将在三维空间中。为了得到7的最后一次出现,您将再次编写</p>
<pre><code>b = np.tile(a.reshape(17,1,1), reps=(1,30,30))
np.argwhere(b==7)[-1]
# [10 29 29]
</code></pre>
<p>它的回报完全符合你的预期。</p>