%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
fin = open("data/lab0-numbers.txt")
nums = [float(x) for x in fin]
nums[:10]
[9.0, 9.0, 6.0, 8.0, 7.0, 7.0, 7.0, 7.0, 2.0, 4.0]
len(nums)
254
plt.hist(nums)
(array([ 20., 12., 27., 31., 18., 21., 69., 30., 14., 12.]), array([ 1. , 1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1, 10. ]), <a list of 10 Patch objects>)
import scipy.stats
scipy.stats.chisquare([ 20., 12., 27., 31., 18., 21., 69., 30., 14., 12.])
Power_divergenceResult(statistic=100.33070866141733, pvalue=1.3488840787890268e-17)
class RANDU():
def __init__(self, s=1):
self.SEED = s
def random(self):
self.SEED *= 65539
self.SEED %= 2 ** 31
return self.SEED / 2 ** 31
r = RANDU(99)
for i in range(10):
print(r.random())
0.0030213785357773304 0.01812785631045699 0.08157473104074597 0.3262976794503629 0.22361349733546376 0.4050018689595163 0.41748973773792386 0.8599216057918966 0.40212199511006474 0.6734375185333192
nums2 = []
for i in range(254):
nums2.append(r.random())
plt.hist(nums2)
(array([ 17., 25., 26., 17., 35., 24., 30., 23., 29., 28.]), array([ 0.00934538, 0.1082365 , 0.20712763, 0.30601875, 0.40490988, 0.503801 , 0.60269213, 0.70158325, 0.80047438, 0.8993655 , 0.99825663]), <a list of 10 Patch objects>)
scipy.stats.chisquare([ 17., 25., 26., 17., 35., 24., 30., 23., 29., 28.])
Power_divergenceResult(statistic=11.118110236220472, pvalue=0.26769991720489827)
x = []
y = []
z = []
for i in range(10000):
x.append(r.random())
y.append(r.random())
z.append(r.random())
plt.scatter(x, y, s=1)
<matplotlib.collections.PathCollection at 0x1132aeb70>
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection = "3d")
ax.view_init(elev=20., azim = 60)
ax.scatter(x, y, z, s=1)
<mpl_toolkits.mplot3d.art3d.Path3DCollection at 0x1133e2b70>