I have an array which has many repeating elements and I want to find the count and the value of the non-zero element that repeats the most. I sort of have it working but I am not sure if this is correct way to do it in python.
Some test code:
import numpy as np
x = np.array([0, 0, 0, 10, 10, 10, 10, 10])
l = list()
for i in np.unique(x):
l.extend((np.count_nonzero(x[x==i]),))
maximum_times = np.max(l)
This tells me the number of times the maximum element has repeated but it does not tell me what that element is and perhaps using the for loop is not a good idea for this but I could not come up with any other pythonic solution.
return_counts=Truetounique().