擅长:python、mysql、java
<p>假设你在寻找整数,就这么简单:</p>
<pre><code>import numpy as np
import random
number_sample = list(range(18))*2 #Get two times numbers from 0 to 17
random.shuffle(number_sample) #Shuffle said numbers
np.array(number_sample).reshape(6,6) #Reshape into matrix
</code></pre>
<h2>输出:</h2>
<pre><code>array([[ 1, 0, 5, 1, 8, 15],
[ 9, 3, 15, 17, 0, 14],
[ 7, 9, 11, 7, 16, 13],
[ 4, 10, 8, 12, 5, 6],
[ 6, 11, 4, 14, 3, 13],
[10, 16, 2, 17, 2, 12]])
</code></pre>
<p>编辑:更改答案以反映问题的更改</p>