[Python] what is the fastest way to get the mode of a numpy array

Discussão em 'Python' iniciado por Stack, Setembro 4, 2025.

  1. Stack

    Stack Membro Participativo

    I have to find the mode of a NumPy array that I read from an hdf5 file. The NumPy array is 1d and contains floating point values.

    my_array=f1[ds_name].value
    mod_value=scipy.stats.mode(my_array)


    My array is 1d and contains around 1M values. It takes about 15 min for my script to return the mode value. Is there any way to make this faster?

    Another question is why scipy.stats.median(my_array) does not work while mode works?


    AttributeError: module 'scipy.stats' has no attribute 'median'
    ​

    Continue reading...

Compartilhe esta Página