Created
March 18, 2017 18:11
-
-
Save devmacrile/ff40e455d210ab8d28dd58b535631815 to your computer and use it in GitHub Desktop.
Twenty sided di sum/difference simulation
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 numpy as np | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
di1 = np.random.random_integers(1, 20, 100000) | |
di2 = np.random.random_integers(1, 20, 100000) | |
values = (di1 + di2) - (np.absolute(di1 - di2)) | |
sample_mean = np.nanmean(values) | |
print np.mean(di1), np.mean(di2) | |
print np.unique(values) | |
print len(np.unique(values)) | |
plt.hist(values, 40, label='Mean = %2.f' % sample_mean) | |
plt.axvline(sample_mean, linewidth=2, linestyle='-', color='k') | |
plt.legend(loc='upper right') | |
plt.xlabel('Sum Minus Difference of Trials') | |
plt.ylabel('Count') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment