Last active
August 29, 2015 13:57
-
-
Save therealmik/9907580 to your computer and use it in GitHub Desktop.
Simple byte frequency count
This file contains 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/python3 | |
import numpy | |
import sys | |
def analyse(fd): | |
result = numpy.zeros(256, dtype=numpy.uint32) | |
while True: | |
data = fd.read(4096) | |
if len(data) == 0: | |
break | |
for c in data: | |
result[c] += 1 | |
return result | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
print("Usage: " + sys.argv[0] + " <file>", file=sys.stderr) | |
sys.exit(1) | |
with open(sys.argv[1], "rb") as fd: | |
result = analyse(fd) | |
for r in result: | |
print(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment