numpy-100 icon indicating copy to clipboard operation
numpy-100 copied to clipboard

Q83 doesn't directly work for floats or sparse integers

Open jeqcho opened this issue 11 months ago • 1 comments

83. How to find the most frequent value in an array?

answer(83)
# Z = np.random.randint(0,10,50)
# print(np.bincount(Z).argmax())

If the array is made out of floats, this doesn't work. If the array is sparse but wide (e.g. [1e9,2e9,2e9]), then this is not efficient as well.

jeqcho avatar Jan 02 '25 15:01 jeqcho

Most frequent value with floats doesn't make really sense unless you use an alsmost_equal function with a given epsilon. As for efficiency, this is not the goal here.

rougier avatar Jan 06 '25 13:01 rougier