我正在尝试填充一个由NumPy数组组成的NumPy数组。每次完成循环迭代时,我都会创建要添加的数组。然后,我想将该数组附加到另一个数组的末尾。例如:
first iteration
np.append([], [1, 2]) => [[1, 2]]
next iteration
np.append([[1, 2]], [3, 4]) => [[1, 2], [3, 4]]
next iteration
np.append([[1, 2], [3, 4]], [5, 6]) => [[1, 2], [3, 4], [5, 6]]
etc.
我尝试使用np.append,但是它返回一个一维数组,即:
[1, 2, 3, 4, 5, 6]
np.vstack
,虽然我建议为了效率先创建一个二维 Python 列表,使用append
,并且只在最后调用np.array
。 - Julien