Python: Get array indexes of quartiles
问题 I am using the following code to calculate the quartiles of a given data set: #!/usr/bin/python import numpy as np series = [1,2,2,2,2,2,2,2,2,2,2,5,5,6,7,8] p1 = 25 p2 = 50 p3 = 75 q1 = np.percentile(series, p1) q2 = np.percentile(series, p2) q3 = np.percentile(series, p3) print('percentile(' + str(p1) + '): ' + str(q1)) print('percentile(' + str(p2) + '): ' + str(q2)) print('percentile(' + str(p3) + '): ' + str(q3)) The percentile function returns the quartiles, however, I would also like