You can use the answer to this other question to get the number of unique elements.
Numpy 1.9 has an optional return_counts keyword argument, so you can just do:
>>> my_array array([[1, 2, 0, 1, 1, 1], [1, 2, 0, 1, 1, 1], [9, 7, 5, 3, 2, 1], [1, 1, 1, 0, 0, 0], [1, 2, 0, 1, 1, 1], [1, 1, 1, 1, 1, 0]]) >>> dt = np.dtype((np.void, my_array.dtype.itemsize * my_array.shape[1])) >>> b = np.ascontiguousarray(my_array).view(dt) >>> unq, cnt = np.unique(b, return_counts=True) >>> unq = unq.view(my_array.dtype).reshape(-1, my_array.shape[1]) >>> unq array([[1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 0], [1, 2, 0, 1, 1, 1], [9, 7, 5, 3, 2, 1]]) >>> cnt array([1, 1, 3, 1])
In earlier versions, you can do this as:
>>> unq, _ = np.unique(b, return_inverse=True) >>> cnt = np.bincount(_) >>> unq = unq.view(my_array.dtype).reshape(-1, my_array.shape[1]) >>> unq array([[1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 0], [1, 2, 0, 1, 1, 1], [9, 7, 5, 3, 2, 1]]) >>> cnt array([1, 1, 3, 1])