Skip to content

Instantly share code, notes, and snippets.

@fernandojunior
Last active April 28, 2016 12:32
Show Gist options
  • Select an option

  • Save fernandojunior/8d0991ea4bdac6bb8528f05336fdab09 to your computer and use it in GitHub Desktop.

Select an option

Save fernandojunior/8d0991ea4bdac6bb8528f05336fdab09 to your computer and use it in GitHub Desktop.
Python, numpy, matrix, functions
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