Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While the iterator-based answers are perfectly fine, if you're working with numpy arrays (as you mention that you are) there are better and faster ways of selecting things:</p> <pre><code>import numpy as np data = np.array([ [100002, 2006, 1.1, 0.01, 6352], [100002, 2006, 1.2, 0.84, 304518], [100002, 2006, 2, 1.52, 148219], [100002, 2007, 1.1, 0.01, 6292], [10002, 2006, 1.1, 0.01, 5968], [10002, 2006, 1.2, 0.25, 104318], [10002, 2007, 1.1, 0.01, 6800], [10002, 2007, 4, 2.03, 25446], [10002, 2008, 1.1, 0.01, 6408] ]) subset1 = data[data[:,0] == 100002] subset2 = data[data[:,0] == 10002] </code></pre> <p>This yields</p> <p>subset1:</p> <pre><code>array([[ 1.00002e+05, 2.006e+03, 1.10e+00, 1.00e-02, 6.352e+03], [ 1.00002e+05, 2.006e+03, 1.20e+00, 8.40e-01, 3.04518e+05], [ 1.00002e+05, 2.006e+03, 2.00e+00, 1.52e+00, 1.48219e+05], [ 1.00002e+05, 2.007e+03, 1.10e+00, 1.00e-02, 6.292e+03]]) </code></pre> <p>subset2:</p> <pre><code>array([[ 1.0002e+04, 2.006e+03, 1.10e+00, 1.00e-02, 5.968e+03], [ 1.0002e+04, 2.006e+03, 1.20e+00, 2.50e-01, 1.04318e+05], [ 1.0002e+04, 2.007e+03, 1.10e+00, 1.00e-02, 6.800e+03], [ 1.0002e+04, 2.007e+03, 4.00e+00, 2.03e+00, 2.5446e+04], [ 1.0002e+04, 2.008e+03, 1.10e+00, 1.00e-02, 6.408e+03]]) </code></pre> <p>If you didn't know the unique values in the first column beforehand, you can use either <a href="http://docs.scipy.org/doc/numpy-1.3.x/reference/generated/numpy.unique1d.html" rel="noreferrer"><code>numpy.unique1d</code></a> or the builtin function <code>set</code> to find them. </p> <p>Edit: I just realized that you wanted to select data where you have unique combinations of two columns... In that case, you might do something like this:</p> <pre><code>col1 = data[:,0] col2 = data[:,1] subsets = {} for val1, val2 in itertools.product(np.unique(col1), np.unique(col2)): subset = data[(col1 == val1) &amp; (col2 == val2)] if np.any(subset): subsets[(val1, val2)] = subset </code></pre> <p>(I'm storing the subsets as a dict, with the key being a tuple of the combination... There are certainly other (and better, depending on what you're doing) ways to do this!)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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