In [3]:
import numpy as np
from matplotlib import pyplot as plt

In [3]:


In [4]:
15*15


Out[4]:
225

In [12]:
# Sample 225 Zahlen von 1 bis 9 aus einer uniform distribution (gleiche Chance fuer alle)
vec = np.random.randint(1,10,225)

In [13]:
# Schauen ob es wirklich uniform ist - mehr oder weniger
plt.hist(vec, bins=9)


Out[13]:
(array([ 24.,  28.,  19.,  32.,  14.,  25.,  34.,  26.,  23.]),
 array([ 1.        ,  1.88888889,  2.77777778,  3.66666667,  4.55555556,
         5.44444444,  6.33333333,  7.22222222,  8.11111111,  9.        ]),
 <a list of 9 Patch objects>)

In [14]:
# Vector in 15 mal 15 Matrix zusammenbasteln
mat = np.reshape(vec, (15, 15))

In [15]:
# Matrix angucken
plt.matshow(mat)


Out[15]:
<matplotlib.image.AxesImage at 0x36fff50>

Kann man auch exakt machen


In [26]:
225./9


Out[26]:
25.0

In [27]:
# Ah, gut, das geht genau auf. Dann machen wir das
exvec = np.tile(np.arange(1,10),25)
np.random.shuffle(exvec)

In [28]:
# Jetzt ist es uniform
plt.hist(exvec, bins=9)


Out[28]:
(array([ 25.,  25.,  25.,  25.,  25.,  25.,  25.,  25.,  25.]),
 array([ 1.        ,  1.88888889,  2.77777778,  3.66666667,  4.55555556,
         5.44444444,  6.33333333,  7.22222222,  8.11111111,  9.        ]),
 <a list of 9 Patch objects>)

In [29]:
exmat = np.reshape(exvec, (15, 15))

In [30]:
# Und angucken
plt.matshow(exmat)


Out[30]:
<matplotlib.image.AxesImage at 0x4228910>

Und in Zahlen


In [32]:
exmat


Out[32]:
array([[4, 9, 3, 9, 6, 7, 1, 4, 2, 7, 1, 7, 6, 6, 1],
       [5, 3, 8, 7, 2, 2, 6, 7, 8, 8, 3, 1, 7, 5, 9],
       [2, 1, 1, 3, 2, 2, 4, 7, 2, 8, 4, 1, 4, 4, 1],
       [4, 3, 9, 7, 4, 2, 3, 4, 2, 7, 7, 6, 7, 8, 5],
       [6, 3, 6, 3, 2, 2, 6, 3, 4, 9, 8, 5, 6, 6, 9],
       [7, 9, 2, 5, 2, 9, 2, 8, 8, 3, 8, 5, 9, 9, 9],
       [9, 6, 1, 6, 8, 5, 6, 5, 6, 9, 5, 9, 1, 8, 8],
       [9, 5, 5, 3, 3, 7, 6, 4, 7, 9, 1, 8, 1, 3, 4],
       [2, 9, 1, 1, 4, 8, 1, 4, 1, 4, 5, 6, 6, 6, 2],
       [1, 7, 5, 3, 4, 7, 5, 5, 4, 7, 5, 9, 1, 9, 8],
       [8, 3, 1, 6, 3, 7, 7, 8, 3, 5, 8, 3, 4, 1, 3],
       [8, 2, 6, 9, 3, 1, 8, 8, 3, 2, 5, 1, 7, 4, 8],
       [5, 5, 5, 2, 4, 2, 9, 1, 9, 8, 1, 9, 4, 2, 3],
       [7, 8, 3, 6, 2, 2, 8, 5, 7, 4, 6, 4, 7, 7, 4],
       [9, 6, 2, 5, 3, 5, 1, 4, 5, 9, 3, 6, 2, 7, 6]])

In [ ]: