Created
February 2, 2017 04:59
-
-
Save tomo3141592653/fa4e54329c216d9f92b2047ea56f6fc9 to your computer and use it in GitHub Desktop.
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
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