Python Np.concatenate ValueError:所有输入数组的维数必须相同
我试图连接,但最终出现了上述错误。我也是python新手Python Np.concatenate ValueError:所有输入数组的维数必须相同,python,np,Python,Np,我试图连接,但最终出现了上述错误。我也是python新手 def cving(x1, x2, x3, x4, x5, y1, y2, y3, y4, y5, ind1, ind2, ind3, ind4, ind5, num): if num == 0: xwhole = np.concatenate((x2, x3, x4, x5), axis=0) yhol = np.concatenate((y2, y3, y4, y5), axis=0) return x1,
def cving(x1, x2, x3, x4, x5, y1, y2, y3, y4, y5, ind1, ind2, ind3, ind4, ind5, num):
if num == 0:
xwhole = np.concatenate((x2, x3, x4, x5), axis=0)
yhol = np.concatenate((y2, y3, y4, y5), axis=0)
return x1, y1, ind1, xwhole, yhol
elif num == 1:
xwhole = np.concatenate((x1, x3, x4, x5), axis=0)
yhol = np.concatenate((y1, y3, y4, y5), axis=0)
return x2, y2, ind2, xwhole, yhol
elif num == 2:
xwhole = np.concatenate((x1, x2, x4, x5), axis=0)
yhol = np.concatenate((y1, y2, y4, y5), axis=0)
return x3, y3, ind3, xwhole, yhol
elif num == 3:
xwhole = np.concatenate((x1, x2, x3, x5), axis=0)
yhol = np.concatenate((y1, y2, y3, y5), axis=0)
return x4, y4, ind4, xwhole, yhol
else:
xwhole = np.concatenate((x1, x2, x3, x4), axis=0)
yhol = np.concatenate((y1, y2, y3, y4), axis=0)
return x5, y5, ind5, xwhole, yhol
以下是x1、x2、x3和x4*的一些输出,以显示用于np.concantate的一些输出
x1 = [[ 1.21537030e+07 5.73132800e+06 1.39127063e-01 ..., 0.00000000e+00
0.00000000e+00 0.00000000e+00]
[ 2.19181650e+07 6.31495600e+06 1.58992826e-01 ..., 0.00000000e+00
0.00000000e+00 0.00000000e+00]
[ 9.35311000e+05 5.93920000e+05 1.40974499e-01 ..., 0.00000000e+00
0.00000000e+00 0.00000000e+00]]
x2= []
x3= []
x4 = [ 1.11088300e+06 1.23238400e+06 1.32048109e-01 1.05878525e-01
9.01409788e-01 1.24716612e+00 7.22766415e-01 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 1.15544472e-01 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
1.54537898e-02 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 7.82815688e-01
1.13352981e-04 1.13352981e-04 0.00000000e+00 0.00000000e+00
8.52792262e-02 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 6.80117887e-04 0.00000000e+00 0.00000000e+00]
错误消息说明了一切:
x1
是2D,而x4
是1D。将这些连接起来是没有意义的。您需要确保所有连接的数组具有相同的维度,例如,向所有1D数组添加维度
x4 = x4[:, np.newaxis]
错误消息说明了一切:
x1
是2D,而x4
是1D。将这些连接起来是没有意义的。您需要确保所有连接的数组具有相同的维度,例如,向所有1D数组添加维度
x4 = x4[:, np.newaxis]