Find unique rows in numpy.array

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

    np.unique when I run it on np.random.random(100).reshape(10,10) returns all the unique individual elements, but you want the unique rows, so first you need to put them into tuples:

    array = #your numpy array of lists
    new_array = [tuple(row) for row in array]
    uniques = np.unique(new_array)
    

    That is the only way I see you changing the types to do what you want, and I am not sure if the list iteration to change to tuples is okay with your "not looping through"

提交回复
热议问题