【问题标题】:Padding doesn't work when size is 63 and 27大小为 63 和 27 时,填充不起作用
【发布时间】:2019-10-06 01:50:51
【问题描述】:

在迭代过程中,除了大小分别为 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 的数组不会被填充。

编辑:粘贴代码时输入错误。

【问题讨论】:

    标签: python numpy svm pad


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-19
      • 2014-04-29
      • 2016-09-02
      • 2021-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多