Skip to content

Instantly share code, notes, and snippets.

@BackSlasher
Last active July 13, 2017 10:35
Show Gist options
  • Save BackSlasher/1e9279cf45098a48db7045058a022b81 to your computer and use it in GitHub Desktop.
Save BackSlasher/1e9279cf45098a48db7045058a022b81 to your computer and use it in GitHub Desktop.
Python Percentile using numpy
#!/usr/bin/env python3
# Backslasher, Jul 2017
#
# Based on https://gist.github.com/vikrum/8202564
import numpy
import argparse
import fileinput
parser = argparse.ArgumentParser(description='Percentile calc')
parser.add_argument('-p', '--percentile', metavar='P', nargs='+', type=float, default=[95], help='Percentile')
parser.add_argument('files', metavar='FILE', nargs='*', help='files to read, if empty, stdin is used')
args = parser.parse_args()
res = numpy.percentile(
[float(line) for line in fileinput.input(files=args.files)],
args.percentile
)
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment