<p dir="auto">Here: <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="x, y : array_like, optional
Values from which to choose. x and y need to have the same shape as condition."><pre class="notranslate"><code class="notranslate">x, y : array_like, optional
Values from which to choose. x and y need to have the same shape as condition.
</code></pre></div>
<p dir="auto">Do they actually need to have the same shape as condition? Also from the docs:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; x = np.arange(9.).reshape(3, 3)
&gt;&gt;&gt; np.where( x &gt; 5 )
(array([2, 2, 2]), array([0, 1, 2]))
&gt;&gt;&gt; x[np.where( x &gt; 3.0 )]               # Note: result is 1D.
array([ 4.,  5.,  6.,  7.,  8.])
&gt;&gt;&gt; np.where(x &lt; 5, x, -1)               # Note: broadcasting.
array([[ 0.,  1.,  2.],
       [ 3.,  4., -1.],
       [-1., -1., -1.]])"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">9.</span>).<span class="pl-en">reshape</span>(<span class="pl-c1">3</span>, <span class="pl-c1">3</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">where</span>( <span class="pl-s1">x</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">5</span> )
(<span class="pl-en">array</span>([<span class="pl-c1">2</span>, <span class="pl-c1">2</span>, <span class="pl-c1">2</span>]), <span class="pl-en">array</span>([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>]))
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">x</span>[<span class="pl-s1">np</span>.<span class="pl-en">where</span>( <span class="pl-s1">x</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">3.0</span> )]               <span class="pl-c"># Note: result is 1D.</span>
<span class="pl-en">array</span>([ <span class="pl-c1">4.</span>,  <span class="pl-c1">5.</span>,  <span class="pl-c1">6.</span>,  <span class="pl-c1">7.</span>,  <span class="pl-c1">8.</span>])
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">where</span>(<span class="pl-s1">x</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">5</span>, <span class="pl-s1">x</span>, <span class="pl-c1">-</span><span class="pl-c1">1</span>)               <span class="pl-c"># Note: broadcasting.</span>
<span class="pl-en">array</span>([[ <span class="pl-c1">0.</span>,  <span class="pl-c1">1.</span>,  <span class="pl-c1">2.</span>],
       [ <span class="pl-c1">3.</span>,  <span class="pl-c1">4.</span>, <span class="pl-c1">-</span><span class="pl-c1">1.</span>],
       [<span class="pl-c1">-</span><span class="pl-c1">1.</span>, <span class="pl-c1">-</span><span class="pl-c1">1.</span>, <span class="pl-c1">-</span><span class="pl-c1">1.</span>]])</pre></div>
<p dir="auto">I often use something like this:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="NumpySlice = Tuple[Union[int, None, slice, ndarray], ...]"><pre class="notranslate"><span class="pl-v">NumpySlice</span> <span class="pl-c1">=</span> <span class="pl-v">Tuple</span>[<span class="pl-v">Union</span>[<span class="pl-s1">int</span>, <span class="pl-c1">None</span>, <span class="pl-s1">slice</span>, <span class="pl-s1">ndarray</span>], ...]</pre></div>
<p dir="auto">but I guess this is more general?</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="NumpySlice = Union[ndarray, Tuple[Union[int, None, slice, ndarray], ...]]"><pre class="notranslate"><span class="pl-v">NumpySlice</span> <span class="pl-c1">=</span> <span class="pl-v">Union</span>[<span class="pl-s1">ndarray</span>, <span class="pl-v">Tuple</span>[<span class="pl-v">Union</span>[<span class="pl-s1">int</span>, <span class="pl-c1">None</span>, <span class="pl-s1">slice</span>, <span class="pl-s1">ndarray</span>], ...]]</pre></div>
<p dir="auto">Also, why aren't <code class="notranslate">_Shape</code> and <code class="notranslate">_ShapeLike</code> exposed as <code class="notranslate">Shape</code> and <code class="notranslate">ShapeLike</code>?  It would be nice to use those and the leading underscore makes them seem private and internal.</p>