ValueError: zero-dimensional arrays cannot be concatenated,

ValueError: zero-dimensional arrays cannot be concatenated,

我有两个轴为 0 的数组(有一个 df 的均值和标准差的结果):

df_cats = 
0      58.609619
1     105.926514
2      76.706543
3      75.405762
4      68.937744
         ...    
75    113.124268
76    125.557373
77    130.514893
78    141.373779
79    109.185791
Length: 80, dtype: float64 0     63.540835
1     55.053429
2     96.221076
3     42.963771
4     57.447924
        ...    
75    42.080755
76    55.309517
77    38.997856
78    57.364695
79    40.197461
Length: 80, dtype: float64

df_dogs = 
0      86.870361
1     153.085205
2      89.576416
3     139.721924
4     107.218750
         ...    
75    129.498291
76    108.676025
77    113.125732
78    145.829346
79    100.272461
Length: 80, dtype: float64 0     57.699218
1     71.814790
2     40.130439
3     44.966932
4     48.964512
        ...    
75    50.994298
76    58.257198
77    89.240987
78    58.945353
79    68.841721
Length: 80, dtype: float64

我正在尝试使用以下代码将两个数组与 axis=1 连接起来:

dogs_and_cats = np.concatenate((df_dogs, df_cats), axis=1)

但总是遇到这个问题:

**ValueError:** zero-dimensional arrays cannot be concatenated

我怎样才能连接它?

一维数组没有第二维。这就是您的问题所在。您可以通过修改这些数组的形状来连接它们,将它们变成只有一列的二维数组,代码如下:

df_dogs.shape=(df_dogs.shape[0],1)
df_cats.shape=(df_cats.shape[0],1)

现在,您可以连接数组。