我想在二维数组中添加三元组

2024-10-02 14:19:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个像这样的numpy2d数组[[[1,1,1],[5,7,3]],[[1,4,5],[8,3,9]]] 我只想在我的一列中添加一个三元组[0,0,0]。你知道吗

我用这种方式尝试函数np.append

np.append(myArray, [[0,0,0]], axis=0)

但它给了我一个错误:

all the input arrays must have same number of dimensions.

所以我试着:

myArray[0]=np.append(myArray[0], [[0,0,0]], axis=0)

获取所需的列,但出现错误:

could not broadcast input array from shape (3,3) into shape (2,3).

有没有办法把我的三胞胎只加到myArray的一列?你知道吗


Tags: the函数input错误np方式数组all