【问题标题】:Reshaping an ndarray for Support Vector Machines重塑支持向量机的 ndarray
【发布时间】:2016-07-07 15:43:27
【问题描述】:

我想使用 SVHN 数据并在其上尝试 SVM。

testdata['X'] <type 'numpy.ndarray'>


(testdata['X']).shape is (32, 32, 3, 26032)

问题是 SVM 需要一个二维数组,而我的是 4。 这意味着我认为我需要重塑它。

我试过了:

(testdata['X']).reshape(2)

给我:

ValueError: total size of new array must be unchanged

【问题讨论】:

    标签: python numpy machine-learning svm


    【解决方案1】:

    使用 reshape 时,您需要在新数组中使用前一个数组中的所有元素,例如,如果您的尺寸是:

    (testdata['X']).shape is (x1, x2, x3, x4)
    

    您可以通过这种方式使用 reshape:

    (testdata['X']).reshape(x1*x2*x3,x4)
    

    或其他一些组合,取决于您的需要

    【讨论】:

      猜你喜欢
      • 2017-11-05
      • 1970-01-01
      • 2014-05-12
      • 2023-03-19
      • 2012-01-31
      • 2019-06-03
      • 2011-06-25
      • 2014-09-24
      相关资源
      最近更新 更多