Efficiently removing duplicate rows from a 2-dimensional Numeric array

Zentrader zentraders at gmail.com
Fri Jul 20 15:39:39 EDT 2007


On Jul 19, 8:35 pm, "Terry Reedy" <tjre... at udel.edu> wrote:
> "Alex Mont" <t-al... at windows.microsoft.com> wrote in message
> 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]].

Converting to a set is the best way to go.  You can convert [1, 2] to
something like "001002" and use that if you first locate, or already
know the largest number.  The brute force way is to loop through the
list and compare this sub-list with list[N+1], then list[N+2], to the
end of the list.  If not found then append to a second list.




More information about the Python-list mailing list