Skip to content

Instantly share code, notes, and snippets.

@tomo3141592653
Created February 2, 2017 04:59
Show Gist options
  • Save tomo3141592653/fa4e54329c216d9f92b2047ea56f6fc9 to your computer and use it in GitHub Desktop.
Save tomo3141592653/fa4e54329c216d9f92b2047ea56f6fc9 to your computer and use it in GitHub Desktop.
import numpy as np
def get_z(arr):
return (np.median(arr) - arr.mean())/arr.std()
arr = (np.random.rand(101) * 10000).astype("int")
z = get_z(arr)
for ite in range(1000000):
i = int(np.random.rand()*101)
if ite %100000 == 0:
print arr
print z
print ite
print ""
arr2 = arr.copy()
arr2[i] += 1
z_new = get_z(arr2)
if(z_new > z and arr2[i] < 10000):
z = z_new
arr = arr2.copy()
continue
arr2 = arr.copy()
arr2[i] -= 1
z_new = get_z(arr2)
if(z_new > z and arr2[i] >= 0):
z = z_new
arr = arr2.copy()
continue
print arr
print z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment