1

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.

venkata krishnan
  • 1,961
  • 1
  • 13
  • 20

1 Answers1

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