我尝试以下操作:如何在连接两个numpy数组时解决错误?
rands = np.empty((0, 10))
rand = np.random.normal(1, 0.1, 10)
rands = np.concatenate((rands,rand),axis=0)
使我有以下错误:
ValueError: all the input arrays must have same number of dimensions
但是,为什么是这个错误?为什么我不能用这个命令在矩阵rands
中追加新行rand
?
备注:
我可以 '修复' 该使用以下命令:
rands = np.concatenate((rands,rand.reshape(1, 10)),axis=0)
,但它看起来不再符合Python,但繁琐......
也许有用更少的括号和重新塑造更好的解决方案...?
嘛'虽然有rands'最初的空行仍然是二维的形状是'(0,10)',这就是为什么它是borks – EdChum
是的,一行是一维的10个元素。我不明白这里的问题是什么...... – Alex
不是在numpy的眼睛里,它不是你仍然会得到与'rands = np.empty((1,10))相同的错误' – EdChum