Как изменить 2D массив в 1D массив в Python - PullRequest
0 голосов
/ 09 декабря 2018

Получение сообщения об ошибке,

Ожидаемый двумерный массив, вместо него получен одномерный массив: массив = [0,00127552 0,00286695 0,00135289 ... 0,00611554 0,02416051 0,00977264].Измените ваши данные, используя array.reshape (-1, 1), если ваши данные имеют одну функцию, или array.reshape (1, -1), если он содержит один образец.

Tried 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.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...