0
我有一列数组包含相同的行,但不同的列。 我打印出数组的形状并检查它们是否有相同的行。Numpy连接为相同的行但列不同的数组
print ("Type x_test : actual",type(x_dump),x_dump.shape, type(actual), actual.shape, pred.shape)
cmp = np.concatenate([x_test,actual,pred],axis = 1)
('Type x_test : actual', <type 'numpy.ndarray'>, (2420L, 4719L), <type 'numpy.ndarray'>, (2420L,), (2420L,))
这给了我一个错误:
ValueError: all the input arrays must have same number of dimensions
我试图复制使用下面的命令,这个错误:
x.shape,x1.shape,x2.shape
Out[772]: ((3L, 1L), (3L, 4L), (3L, 1L))
np.concatenate([x,x1,x2],axis=1)
Out[764]:
array([[ 0, 0, 1, 2, 3, 0],
[ 1, 4, 5, 6, 7, 1],
[ 2, 8, 9, 10, 11, 2]])
我没有在这里得到任何错误。有没有人面临类似的问题?
编辑1:在写完这个问题后,我发现尺寸是不同的。 @Gareth Rees:精美地解释了numpy数组(R,1)和(R,)here之间的差别。
上的使用:
# Reshape and concatenate
actual = actual.reshape(len(actual),1)
pred = pred.reshape(len(pred),1)
编辑2:标记关闭这个答案的Difference between numpy.array shape (R, 1) and (R,)重复。
这是什么问题?结果似乎是正确的。你能更准确地知道你想要做什么吗? – fonfonx
@fonfonx我的第一个命令是给出错误。形状也是(2420L,)而不是(2420L,1L)。即使我使用x_dump.reshape(2420,1)它不起作用。为什么col值在x_dump.shape中为空 – Tammy
“形状也是(2420L,)而不是(2420L,1L)” - 这是你的问题。你需要重塑形状为'(2420L,)'的物体以具有形状'(2420L,1)'。 – Eric