Created
August 8, 2014 14:24
-
-
Save heshed/376e2327918f9bb44c93 to your computer and use it in GitHub Desktop.
bincount of digitize random floats
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/env python | |
#-*- coding : utf-8 -*- | |
''' | |
Created on 2014. 8. 8. | |
@author: binaa1@gmail.com | |
''' | |
import time | |
import numpy as np | |
def elapsed(start, msg): | |
print 'elapsed', time.time() - start, 'sec', msg | |
def main(): | |
start = time.time() | |
x = np.random.random_sample((3000000,)) | |
elapsed(start, 'random list') | |
start = time.time() | |
bins = np.array(np.arange(0.0, 1.001, 0.001)) | |
elapsed(start, 'bins') | |
start = time.time() | |
indices = np.digitize(x, bins) | |
elapsed(start, 'digitize') | |
start = time.time() | |
bincount = np.bincount(indices) | |
print len(bincount), bincount | |
elapsed(start, 'bincount') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment