%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
nums = []
fin = open("lab0-numbers.txt")
for line in fin:
nums.append(float(line.strip()))
plt.hist(nums)
(array([ 3., 4., 4., 8., 4., 6., 18., 5., 7., 3.]), 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([ 3., 4., 4., 8., 4., 6., 18., 5., 7., 3.])
(28.967741935483868, 0.00065620966093077532)
class RANDU():
def __init__(self, s=1):
self.SEED = s
def random(self):
self.SEED *= 65539
self.SEED %= 2 ** 31
return float(self.SEED) / 2 ** 31
r = RANDU()
for i in range(10):
print r.random()
3.05189751089e-05 0.000183109659702 0.00082398718223 0.00329593615606 0.0123597322963 0.0444949683733 0.155732219573 0.533938602079 0.802041636314 0.0068023991771
nums2 = []
for i in range(60):
nums2.append(r.random())
plt.hist(nums2)
(array([ 7., 1., 2., 9., 6., 5., 6., 6., 11., 7.]), array([ 0.01345624, 0.10821801, 0.20297978, 0.29774156, 0.39250333, 0.4872651 , 0.58202687, 0.67678864, 0.77155042, 0.86631219, 0.96107396]), <a list of 10 Patch objects>)
scipy.stats.chisquare([ 7., 1., 2., 9., 6., 5., 6., 6., 11., 7.])
(12.999999999999998, 0.16260626219029975)
x = []
y = []
z = []
for i in range(10000):
x.append(r.random())
y.append(r.random())
z.append(r.random())
from mpl_toolkits.mplot3d import Axes3D
plt.scatter(y, z, s=1)
<matplotlib.collections.PathCollection at 0x1195631d0>
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.Patch3DCollection at 0x11a03d050>
x = []
y = []
z = []
for i in range(10000):
x.append(np.random.random())
y.append(np.random.random())
z.append(np.random.random())
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.Patch3DCollection at 0x119509f50>