Find unique rows in numpy.array

后端 未结 20 2858
独厮守ぢ
独厮守ぢ 2020-11-21 10:57

I need to find unique rows in a numpy.array.

For example:

>>> a # I have
array([[1, 1, 1, 0, 0, 0],
       [0, 1, 1, 1, 0, 0],
         


        
20条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 11:57

    Why not use drop_duplicates from pandas:

    >>> timeit pd.DataFrame(image.reshape(-1,3)).drop_duplicates().values
    1 loops, best of 3: 3.08 s per loop
    
    >>> timeit np.vstack({tuple(r) for r in image.reshape(-1,3)})
    1 loops, best of 3: 51 s per loop
    

提交回复
热议问题