JosueCom:

Resulting in a 2d array e.i. running unique on each row with count


This wouldn’t necessary result in a 2-dimensional tensor, since each row might contain a different number of unique elements and I think you would need to iterate the rows:
x = torch.tensor([[0, 0, 0],
                  [1, 1, 2]])

for x_ in x.split(1, 0):
    print(torch.unique(x_, return_counts=True))

> (tensor([0]), tensor([3]))
  (tensor([1, 2]), tensor([2, 1]))