收到错误消息,

预期的2D阵列,改为获得1D阵列:array = [0.00127552 0.00286695 0.00135289 ... 0.00611554 0.02416051 0.00977264] . 如果数据具有单个要素,则使用array.reshape(-1,1)重新整形数据;如果数据包含单个样本,则使用array.reshape(1,-1)重新整形数据 .

试过 tstArray.reshape(1,-1) 但没有运气 .

import numpy as np
import matplotlib.pyplot as plt
import skimage.feature
from sklearn.decomposition import PCA
trnImages = np.load('trnImage.npy')
tstImages = np.load('tstImage.npy')
trnLabels = np.load('trnLabel.npy')
tstLabels = np.load('tstLabel.npy')
trnidx = 20
trnImages.shape
from sklearn.svm import SVC
import tensorflow.keras as keras


def computeFeatures(image):
# This function computes the HOG features with the parsed hyperparameters    and returns the features as hog_feature. 
 # By setting visualize=True we obtain an image, hog_as_image, which can be plotted for insight into extracted HOG features.
hog_feature, hog_as_image = skimage.feature.hog(image, visualize=True, block_norm='L2-Hys')
return hog_feature
rnArray = np.zeros([10000,324]) 
tstArray = np.zeros([1000,324])

for i in range (0, 10000 ):
trnFeatures = computeFeatures(trnImages[:,:,:,i])
trnArray[i,:] = trnFeatures




ValueError: Expected 2D array, got 1D array instead:
array=[0.00127552 0.00286695 0.00135289 ... 0.00611554 0.02416051    0.00977264].
Reshape your data either using array.reshape(-1, 1) if your data has a   single feature or array.reshape(1, -1) if it contains a single sample.