Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>np.array(list(set(map(tuple, input)))) </code></pre> <p>returns</p> <pre><code>array([[4, 5], [2, 3], [1, 1]]) </code></pre> <p><strong>UPDATE 1:</strong> If you want to remove the <code>[1, 1]</code> too (because it appears more than once), you can do:</p> <pre><code>from collections import Counter np.array([k for k, v in Counter(map(tuple, input)).iteritems() if v == 1]) </code></pre> <p>returns</p> <pre><code>array([[4, 5], [2, 3]]) </code></pre> <p><strong>UPDATE 2:</strong> with <code>input=[[1,1,2], [1,1,3], [2,3,4], [4,5,5], [1,1,7]]</code>:</p> <pre><code>input=[[1,1,2], [1,1,3], [2,3,4], [4,5,5], [1,1,7]] d = {} for a in input: d.setdefault(tuple(a[:2]), []).append(a[2]) </code></pre> <p><code>d</code> is now:</p> <pre><code>{(1, 1): [2, 3, 7], (2, 3): [4], (4, 5): [5]} </code></pre> <p>so we want to take all key-value pairs, that have single values and re-create the arrays:</p> <pre><code>np.array([k+tuple(v) for k,v in d.iteritems() if len(v) == 1]) </code></pre> <p>returns:</p> <pre><code>array([[4, 5, 5], [2, 3, 4]]) </code></pre> <p><strong>UPDATE 3:</strong> For larger arrays, you can adapt my previous solution to:</p> <pre><code>import numpy as np input = [[1,1,3,5,6,6],[1,1,4,4,5,6],[1,3,4,5,6,7],[3,4,6,7,7,6],[1,1,4,6,88,7],[3,3,3,3,3,3],[456,6,5,343,435,5]] d = {} for a in input: d.setdefault(tuple(a[:2]), []).append(a) np.array([v for v in d.itervalues() if len(v) == 1]) </code></pre> <p>returns:</p> <pre><code>array([[[456, 6, 5, 343, 435, 5]], [[ 1, 3, 4, 5, 6, 7]], [[ 3, 4, 6, 7, 7, 6]], [[ 3, 3, 3, 3, 3, 3]]]) </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