相关疑难解决方法(0)

如何将新行添加到空的numpy数组中

使用标准Python数组,我可以执行以下操作:

arr = []
arr.append([1,2,3])
arr.append([4,5,6])
# arr is now [[1,2,3],[4,5,6]]
Run Code Online (Sandbox Code Playgroud)

但是,我不能在numpy做同样的事情.例如:

arr = np.array([])
arr = np.append(arr, np.array([1,2,3]))
arr = np.append(arr, np.array([4,5,6]))
# arr is now [1,2,3,4,5,6]
Run Code Online (Sandbox Code Playgroud)

我也研究过vstack,但是当我vstack在一个空阵列上使用时,我得到:

ValueError: all the input array dimensions except for the concatenation axis must match exactly
Run Code Online (Sandbox Code Playgroud)

那么如何在numpy中向空数组添加一个新行呢?

python numpy scipy

129
推荐指数
3
解决办法
19万
查看次数

标签 统计

numpy ×1

python ×1

scipy ×1