Find unique rows in numpy.array

后端 未结 20 3117
独厮守ぢ
独厮守ぢ 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:40

    np.unique works given a list of tuples:

    >>> np.unique([(1, 1), (2, 2), (3, 3), (4, 4), (2, 2)])
    Out[9]: 
    array([[1, 1],
           [2, 2],
           [3, 3],
           [4, 4]])
    

    With a list of lists it raises a TypeError: unhashable type: 'list'

提交回复
热议问题