In [3]:
import numpy as np
from matplotlib import pyplot as plt
In [3]:
In [4]:
15*15
Out[4]:
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]:
In [14]:
# Vector in 15 mal 15 Matrix zusammenbasteln
mat = np.reshape(vec, (15, 15))
In [15]:
# Matrix angucken
plt.matshow(mat)
Out[15]:
In [26]:
225./9
Out[26]:
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]:
In [29]:
exmat = np.reshape(exvec, (15, 15))
In [30]:
# Und angucken
plt.matshow(exmat)
Out[30]:
In [32]:
exmat
Out[32]:
In [ ]: