Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>from numpy import * eps = 0.1 #ASSUMING the second arrow is sorted (otherwise sort it first) a= array( [[1, 1.2, 3], [2, 2.2, 3], [3, 2.25, 1], [4, 2.28, 4], [5, 3.2, 8], [6, 4.2, 10], [7, 4.21, 3], [8, 4.25, 4], [9, 4.28, 1], [10, 5.2, 10], ]) # expected result # a= [[1, 1.2, 3], # [3, 2.25, 1], # [5, 3.2, 8], # [9, 4.28, 1], # [10, 5.2, 10], # ] n = shape(a)[0] b = a[:,1] a1 = a[ (diff(b)&lt;eps) ] #indexes of some False that could be True. #these indexes should be checked backwards #and evtl. added to a1 indexes = where((diff(b)&lt;eps)==False)[0][1:] for index in indexes: if b[index] - b[index-1]&lt;eps: a1 = vstack( (a1,a[index,:]) ) #sort array a1 = a1[lexsort( (a1[:,1],a1[:,1]))] groups = where(diff(a1[:,1])&gt;eps)[0] i = 0 # get min of groups for g in groups: ag = a1[i:g+1,2] Ag = a1[i:g+1,:] if i == 0: a2 = Ag [ ag == min(ag) ] else: a2 = vstack( (a2, Ag [ ag == min(ag) ] ) ) i = g+1 #add last group ag = a1[g+1:,2] Ag = a1[g+1:,:] a2 = vstack( (a2, Ag [ ag == min(ag) ]) ) #the elements that build no groups result = a[ in1d(a[:,0], [ int(i) for i in a[:,0] if i not in a1[:,0] ]) ] # add the elements of a2, these are the minimal elements of each group result = vstack( (result, a2) ) # sort the result (optional) result = result[lexsort( (result[:,0], result[:,0]))] print "final result\n", result </code></pre> <p>Here is the output of this code</p> <pre><code>In [1]: run filter.py final result [[ 1. 1.2 3. ] [ 3. 2.25 1. ] [ 5. 3.2 8. ] [ 9. 4.28 1. ] [ 10. 5.2 10. ]] </code></pre>
    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. 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