擅长:python、mysql、java
<p>你的方法的问题是你没有建立一个列表,比如这个列表。相反,您只是从<code>np.asarray</code>索引一个项目,而从不保存值。此外,您甚至不想索引<code>np.asarray</code>,而是希望将一个列表传递给它的构造函数。你知道吗</p>
<p>您需要创建一个临时列表,以便在每次<code>challenges</code>的迭代中保存<code>self.simulate(c)</code>的返回值,并将<em>该列表传递给<code>np.asarray</code>:</p>
<pre><code>temp = []
for c in challenges:
temp.append(self.simulate(c))
array = np.asarray(temp)
</code></pre>
<p>另外,为了让您知道,您所指的“pythonic循环”通常称为<a href="https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions" rel="nofollow noreferrer"><em>list comprehension</em></a>。”Pythonic”只是我们Python社区成员用来描述Python语言及其理想的一个名称。你知道吗</p>