linuxCLI and jq. has jq a built in function to compute percentiles ?
- User
linuxCLI and jq. has jq a built in function to compute percentiles ?
- Assistant
No, jq does not provide a built-in function specifically for computing percentiles. However, you can define your own function that sorts the array and then calculates the appropriate index for the desired percentile.
For example, here’s a simple custom function that computes a p-th percentile (where p is given as a number between 0 and 100):
jq -n --argjson data '[10, 20, 30, 40, 50]' ' def percentile(p): # Sort the array . as $arr | $arr | sort # Compute the index based on p, using linear interpolation (here using floor for simplicity) | .[ ((length - 1) * (p / 100)) | floor ]; # Compute and output the 90th percentile $data | percentile(90) '
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.