I have this kind of array a = np.array([[-999, 9, 7, 3], [2, 1, -999, 1], [1, 5, 4, 6], [0, 6, -999, 9], [1, -999, -999, 6], [8, 4, 4, 8]]) I want to get 40% percentile of each row in that array where it is not equal -999 If I use np.percentile(a, 40, axis=1) I will get array([ 3.8, 1. , 4.2, 1.2, -799. , 4.8]) which is still include -999 the output I want will be like this [ 6.2, # 3 or 7 also ok 1, 4.2, # 4 or 5 also ok 4.8, # 0 or 6 also ok 1, 4 ] Thank you Continue reading...