Basically I want to build a function to ACCEPT a non-empty numpy array of labels as input , RETURN the value that appears most frequently in that array. In the case of of a tie, RETURN the value in the tie that appears first in the array.
Asked
Active
Viewed 487 times
1
-
1What you have tried so far? Please share some code. – Sami Ahmed Siddiqui Jul 19 '19 at 08:58
-
Possible duplicate of [Find the most frequent number in a numpy vector](https://stackoverflow.com/questions/6252280/find-the-most-frequent-number-in-a-numpy-vector) – FObersteiner Jul 19 '19 at 09:56
1 Answers
1
Resuing the answer from https://stackoverflow.com/a/28736715/4578111
def frequent_label(labels):
(values,counts) = np.unique(labels,return_counts=True)
ind=np.argmax(counts)
return values[ind]

venkata krishnan
- 1,961
- 1
- 13
- 20
-
if you find this answer helpful, please mark it as accepted answer, and feel free to upvote. – venkata krishnan Jul 19 '19 at 09:56