当尺寸为63和27时,填充不起作用

2024-04-19 12:58:16 发布

您现在位置:Python中文网/ 问答频道 /正文

在迭代过程中,几乎100个数组中的所有数组都被填充,只有两个数组的大小分别为63和27。因此,由于特征数组的大小不同,SVM无法工作

我尝试在底部再次迭代,但没有成功。试图使用条件语句更改维度,但无效

for idx1, f in enumerate(feature):
        if idx1 >= 50: break
        current_feature.append(f[2])
        current_feature.append(f[3])
        current_feature.append(f[4])

    #fixations.append(feature.feature_list)
    current_feature = np.array(current_feature)
    pad_amount = 150 - current_feature.size
    prev = current_feature.size
    np.pad(current_feature, (0, pad_amount), 'constant')
    if current_feature.size != 150:
        np.pad(current_feature, (0, pad_amount), 'constant')
        print(prev)
        print(current_feature.size)
    feed.append(current_feature)

在100个功能阵列中,仅创建了两个尺寸为67和27的阵列,它们不会被填充

编辑:粘贴代码时键入


Tags: sizeif过程np特征数组currentamount
1条回答
网友
1楼 · 发布于 2024-04-19 12:58:16

np.pad不在原地更改数组,它将返回新数组。试试current_feature = np.pad(current_feature, (0, pad_amount), 'constant')

(出于同样的原因,您可以删除np.pad(current_feature, (0, pad_amount), 'constant')的第一个外观)

相关问题 更多 >