回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我创建了一个脚本来生成一个列表:</p>
<pre><code>import random
nota1 = range (5, 11)
nota2 = range (5, 11)
nota3 = range (5, 11)
nota4 = range (0, 2)
dados = []
for i in range(1000):
dados_dado = []
n1 = random.choice(nota1)
n2 = random.choice(nota2)
n3 = random.choice(nota3)
n4 = random.choice(nota4)
n1 = float (n1)
n2 = float (n2)
n3 = float (n3)
n4 = float (n4)
dados_dado.append (n1)
dados_dado.append (n2)
dados_dado.append (n3)
dados_dado.append (n4)
dados.append (dados_dado)
</code></pre>
<p>当我打印<code>type (dados)</code>python return:<code><type 'list'></code>时,一个巨大的列表如下所示:</p>
<pre><code>[[5.0, 8.0, 10.0, 1.0], [8.0, 9.0, 9.0, 1.0], [7.0, 5.0, 6.0, 1.0], [5.0, 8.0, 7.0, 0.0], [9.0, 7.0, 10.0, 0.0], [6.0, 7.0, 9.0, 1.0], [6.0, 9.0, 8.0, 1.0]]
</code></pre>
<p>我需要把它转换成<code><type 'numpy.ndarray'></code>,所以我做了:</p>
<pre><code>data = np.array(dados)
</code></pre>
<p>我期望的回报是这样的:</p>
<pre><code> [[ 6.8 3.2 5.9 2.3]
[ 6.7 3.3 5.7 2.5]
[ 6.7 3. 5.2 2.3]
[ 6.3 2.5 5. 1.9]
[ 6.5 3. 5.2 2. ]
[ 6.2 3.4 5.4 2.3]
[ 5.9 3. 5.1 1.8]]
</code></pre>
<p>但是,我得到的是:</p>
<pre><code> [[ 7. 10. 6. 1.]
[ 8. 6. 6. 1.]
[ 6. 9. 5. 0.]
...,
[ 9. 7. 10. 0.]
[ 6. 7. 9. 1.]
[ 6. 9. 8. 1.]]
</code></pre>
<p>我做错什么了</p>