【发布时间】:2020-09-14 16:57:39
【问题描述】:
我真的希望不要错过之前已经澄清过的东西,但我在这里找不到东西。
任务看起来很简单,但我失败了。我想在 for 循环中不断地将一个 numpy 数组附加到另一个数组:
step_n = 10
steps = np.empty([step_n,1])
for n in range(step_n):
step = np.random.choice([-1, 0, 1], size=(1,2))
#steps.append(step) -> if would be lists, I would do it like that
a = np.append(steps,step)
#something will be checked after each n
print(a)
输出应该是 <class 'numpy.ndarray'> 类型的 ofc 并且看起来像:
[[-1. 0.]
[ 0. 0.]
[-1. -1.]
[ 1. -1.]
[ 1. 1.]
[ 0. -1.]
[-1. 1.]
[-1. 0.]
[ 0. -1.]
[ 1. 1.]]
但是,由于某些(很可能是显而易见的)原因,代码失败了。 谁能给我一个提示?
【问题讨论】: