count occurrences of arrays in multidimensional arrays in python

后端 未结 5 1715
醉酒成梦
醉酒成梦 2020-12-20 18:11

I have the following type of arrays:

a = array([[1,1,1],
           [1,1,1],
           [1,1,1],
           [2,2,2],
           [2,2,2],
           [2,2,2],
         


        
5条回答
  •  鱼传尺愫
    2020-12-20 18:43

    Since numpy-1.13.0, np.unique can be used with axis argument:

    >>> np.unique(a, axis=0, return_counts=True)
    
    (array([[1, 1, 1],
            [2, 2, 2],
            [3, 3, 0]]), array([3, 3, 3]))
    

提交回复
热议问题