Is there a way that collections.Counter
doesn't count/ignores a given value (here 0):
from collections import Counter
import numpy as np
idx = np.random.randint(4, size=(100,100))
most_common = np.zeros(100)
num_most_common = np.zeros(100)
for i in range(100):
most_common[i], num_most_common[i] = Counter(idx[i, :]).most_common(1)[0]
So if 0
is the most common value it should give the second most common value. In addition, is there a way to avoid the for loop in this case?