NumPy Reference: Indexing
Note: The expression a < mean
produces a boolean array, like:
[[False, False, True, False, False, False, True, True, True],
[True, True, False, False, True, True, False, True, True]]
def filter(): a = np.array([ (20,20,10,23,26,32,10,5,0), (0,2,50,20,0,1,28,5,0) ]) mean = a.mean() print("mean",mean) #14.0 print(a[a<mean]) #[10 10 5 0 0 2 0 1 5 0] # replace all which value which is less than mean value a[a<mean]=mean print(a) """ [[20 20 14 23 26 32 14 14 14] [14 14 50 20 14 14 28 14 14]] """ if __name__ == "__main__": filter()