我想使用SVHN数据并尝试在其上应用SVM。
testdata['X'] <type 'numpy.ndarray'>(testdata['X']).shape is (32, 32, 3, 26032)
问题在于SVM需要一个二维数组,而我的却是四维的。这意味着我需要重塑它,我想。
我尝试了:
(testdata['X']).reshape(2)
结果得到:
ValueError: total size of new array must be unchanged
回答:
在使用reshape时,你需要在新数组中使用之前数组的所有元素,例如,如果你的维度是:
(testdata['X']).shape is (x1, x2, x3, x4)
你可以这样使用reshape:
(testdata['X']).reshape(x1*x2*x3,x4)
或者根据你的需求使用其他组合