Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>[Edited to put the simpler approach first.]</p> <p>In practice I'd probably just do:</p> <pre><code>In [166]: d = dict(m_out[:,::-1]) In [167]: [(k, d[k]) for k in eqn_out if k in d] Out[167]: [(7, 6), (9, 8), (11, 10), (13, 12), (15, 14), (17, 16)] </code></pre> <p>But for fun, sticking in numpy, how about something like:</p> <p>[Updated: better numpy method]:</p> <pre><code>In [15]: m_out[np.in1d(v, eqn_out)][:, ::-1] Out[15]: array([[ 7, 6], [ 9, 8], [11, 10], [13, 12], [15, 14], [17, 16]]) </code></pre> <p>Or my original numpy approach:</p> <pre><code>In [150]: import numpy as np In [151]: m_out = np.arange(50).reshape(25,2) In [152]: v = m_out[:,1] In [153]: eqn_out = np.arange(7, 18) In [154]: eqn_out Out[154]: array([ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) </code></pre> <p>Keep only the values we know about:</p> <pre><code>In [155]: np.intersect1d(eqn_out, v) Out[155]: array([ 7, 9, 11, 13, 15, 17]) </code></pre> <p>Find where they're located at (assumes the data is sorted!!): </p> <pre><code>In [156]: v.searchsorted(np.intersect1d(eqn_out, v)) Out[156]: array([3, 4, 5, 6, 7, 8]) </code></pre> <p>Use these indices for selection purposes:</p> <pre><code>In [157]: m_out[v.searchsorted(np.intersect1d(eqn_out, v))] Out[157]: array([[ 6, 7], [ 8, 9], [10, 11], [12, 13], [14, 15], [16, 17]]) </code></pre> <p>Flip:</p> <pre><code>In [158]: m_out[v.searchsorted(np.intersect1d(eqn_out, v))][:,::-1] Out[158]: array([[ 7, 6], [ 9, 8], [11, 10], [13, 12], [15, 14], [17, 16]]) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload