Get amount of unique elements in numpy
set(arr.flatten()) will create your desired result. Not sure about how fast it is though.
Output:
{1, 2, 3}
Edit:
You wanted the number of unique elements, so you wrap the whole thing in len()
I have an array
arr = np.array([[1,1,2], [1,2,3]]).
I want to get amount of unique element for each row and count mean
I can do this np.array([len(np.unique(row)) for row in arr]).mean().
But seems, that it's a slow way. Is there another faster approach?