我想知道numpy是否可以自动提供第二个dim,因为我不想每次都计算,例如:
a1 = np.array([[ 0, 1, 2, 3, 4, 5],[ 6, 7, 8, 9, 10, 11]])
a2 = np.reshape(a1,(3, a1.shape[0] * a1.shape[1] / 3))
但是,如果使用a2 = np.reshape(a1, (3, ))
它显示错误:
无法将大小为12的数组整形为形状(3,(
对额外维度使用-1
:
a2 = np.reshape(a1,(3, -1))
或者简单一点的
a2 = a1.reshape(3,-1)