Given multiple prediction vectors, how to efficiently obtain the label with most votes (in numpy/pytorch)?
I have 3 vectors representing the 3 different predictions of labels for the same data:
P1=[31, 22, 11, 10,  9, 9, 0, 0, 23 ....]  # length over 1M
P2=[31, 22, 12, 10,  8, 9, 0, 0, 30 ....]  # length over 1M
P3=[30, 22, 12, 11,  8, 9, 0, 1, 31 ....]  # length over 1M

Ans= [31, 22, 12, 10, 8, 9, 0, 0, 23, ....]

The basic idea is if a prediction has the highest vote count (e.g. &quot;31&quot; has count 2 in the first column), we pick it, but if all candidates have a different vote (e.g. &quot;23&quot;, &quot;30&quot;, &quot;31&quot; in the last column), we can pick any one of them.
These vectors may be numpy array, list or pytorch tensor. Considering the length of such vector is over 1000,000, what's the most efficient way (mainly runtime) to find Ans?

You can take the mode of the tensors:
t = torch.tensor([P1,P2,P3])
t.mode(0).values

tensor([31, 22, 12, 10,  8,  9,  0,  0, 23])

