daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest Mar 18th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import time
  4.  
  5. ns = 2**(np.arange(4,14))
  6. times = np.zeros_like(ns, dtype='float')
  7. rep = 10
  8.  
  9. for count, n in enumerate(ns):
  10.     im = np.random.random((n,n))
  11.     im1 = np.copy(im)
  12.    
  13.     trials = np.zeros(rep)
  14.     for c in range(rep):
  15.         t = time.time()
  16.         im1 = np.copy(im)
  17.         trials[c] = (time.time()-t)* 1e3 # convert sec to ms
  18.    
  19.     times[count] = np.median(trials)
  20.        
  21.    
  22.     print n, times[count]
  23.  
  24. plt.plot(ns, times, 'ro')
  25.  
  26. plt.xscale('log')
  27. plt.yscale('log')
  28.  
  29. plt.xlabel('Array size (nxn)')
  30. plt.ylabel('Time (sec)')
  31.  
  32.  
  33.  
  34.  
  35. plt.show()
RAW Paste Data
Top