Percentiles / Quantiles
Percentiles / Quantiles
Compute percentiles of a dataset using linear interpolation.
Function Arguments
x: list or array- Numeric dataq: list or array- Percentile values (0-100)
Examples
Input: x=[1,2,3,4], q=[25,50,75]
Output: [1.75, 2.5, 3.25]
Input: x=[1,2,3,4,5], q=[50]
Output: [3.0]
Input: x=[4,1,3,2], q=[25,75]
Output: [1.75, 3.25]
Hint 1
Use np.percentile() with method='linear'.
Hint 2
Convert inputs to NumPy arrays first.
Hint 3
Return result as NumPy array.
Requirements
- Return NumPy array of percentile values
- Use linear interpolation method
- No sorting loops; use
np.sort() - Handle edge cases (0%, 100%)
Constraints
- len(x) ≥ 1, 0 ≤ q ≤ 100
- NumPy only; time limit: 300ms
Try Similar Problems
Log in to take notes on this problem
Accepts: array
Accepts: array
Percentiles / Quantiles
Percentiles / Quantiles
Compute percentiles of a dataset using linear interpolation.
Function Arguments
x: list or array- Numeric dataq: list or array- Percentile values (0-100)
Examples
Input: x=[1,2,3,4], q=[25,50,75]
Output: [1.75, 2.5, 3.25]
Input: x=[1,2,3,4,5], q=[50]
Output: [3.0]
Input: x=[4,1,3,2], q=[25,75]
Output: [1.75, 3.25]
Hint 1
Use np.percentile() with method='linear'.
Hint 2
Convert inputs to NumPy arrays first.
Hint 3
Return result as NumPy array.
Requirements
- Return NumPy array of percentile values
- Use linear interpolation method
- No sorting loops; use
np.sort() - Handle edge cases (0%, 100%)
Constraints
- len(x) ≥ 1, 0 ≤ q ≤ 100
- NumPy only; time limit: 300ms
Try Similar Problems
Log in to take notes on this problem
Accepts: array
Accepts: array