在迭代过程中,除了两个大小分别为63和27的数组外,几乎所有100个数组都被填充。结果,由于要素数组的大小差异,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的数组。
编辑:在粘贴代码时输入错误。
答案 0 :(得分:1)
np.pad不会在原位置更改数组,而是返回新数组。尝试current_feature = np.pad(current_feature, (0, pad_amount), 'constant')
(出于相同的原因,您可以删除np.pad(current_feature, (0, pad_amount), 'constant')
的首次出现。)