Efficiently removing duplicate rows from a 2-dimensional Numeric array

Terry Reedy tjreedy at udel.edu
Thu Jul 19 23:35:10 EDT 2007


"Alex Mont" <t-alexm at windows.microsoft.com> wrote in message 
news:76EEE12626B7A84EBACE67EC513AE53D060F8CE9 at WIN-MSG-20.wingroup.windeploy.ntdev.microsoft.com...
I have a 2-dimensional Numeric array with the shape (2,N) and I want to
remove all duplicate rows from the array. For example if I start out
with:
[[1,2],
[1,3],
[1,2],
[2,3]]

I want to end up with
[[1,2],
[1,3],
[2,3]].
=================================================

If you can define a 1-1 map of rows to ints (or even float or strings), you 
can put intsnumbers into a set and then convert (unique) items back to 
rows.  For example above, the obvious 10*r[0] + r[1] would do.  So would 
chr(r[0]) + chr(r[1]).  More generally, you need the min and max of the 
second numbers and not have them be too far apart/

tjr






More information about the Python-list mailing list