Last active
July 13, 2017 10:35
-
-
Save BackSlasher/1e9279cf45098a48db7045058a022b81 to your computer and use it in GitHub Desktop.
Python Percentile using numpy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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