Last active
April 28, 2016 12:32
-
-
Save fernandojunior/8d0991ea4bdac6bb8528f05336fdab09 to your computer and use it in GitHub Desktop.
Python, numpy, matrix, functions
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
| import time | |
| import numpy as np | |
| ROW = int(1 * 1e5) | |
| COL = int(1 * 1e3) | |
| data = np.random.rand(ROW, COL) | |
| functions = [np.mean, np.median, np.std, np.var, np.sum] | |
| def ze(): | |
| values = [] | |
| for col in range(COL): | |
| for function in functions: | |
| values.extend([round(function(data[:, col]),2)]) | |
| return values | |
| def modificado(): | |
| return np.round([function(data, axis=0) for function in functions], 2) | |
| def exectime(fn): | |
| start_time = time.time() | |
| fn() | |
| print("--- %s seconds ---" % (time.time() - start_time)) | |
| exectime(ze) | |
| exectime(modificado) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment