ValueError:无法将大小为9912406的数组重塑为形状(28873,12642)

时间:2018-01-14 03:51:51

标签: python

Sebastian Raschka研究PYTHON MACHINE LEARNING我有错误“无法重塑大小为9912406的阵列(28873,12642)”有人可以帮我吗? 我不明白为什么会发生这种情况,也许有人遇到同样的问题,我已经更新了所有模块 我在这里跟随第13章github.com/PacktPublishing / ...我可以使用什么而不是重塑或解决这个问题

import struct

def load_mnist(path, kind='train'):
    """Load MNIST data from `path`"""
    labels_path = os.path.join(path, 
                               '%s-labels-idx1-ubyte.gz' % kind)
    images_path = os.path.join(path, 
                               '%s-images-idx3-ubyte.gz' % kind)

    with open(labels_path, 'rb') as lbpath:
        magic, n = struct.unpack('>II', 
                                 lbpath.read(8))
        labels = np.fromfile(lbpath, 
                             dtype=np.uint8)

    with open(images_path, 'rb') as imgpath:
        magic, num, rows, cols = struct.unpack(">IIII", 
                                               imgpath.read(16))
        images = np.fromfile(imgpath, 
                             dtype=np.uint8).reshape(len(labels), 784)
        images = ((images / 255.) - .5) * 2

    return images, labels



## loading the data
#\
path='C:/Users/IbharAdolfo/Downloads/'

X_train, y_train = load_mnist(path, kind='train')
print('Rows: %d,  Columns: %d' %(X_train.shape[0], 
                                 X_train.shape[1]))

X_test, y_test = load_mnist(path, kind='t10k')
print('Rows: %d,  Columns: %d' %(X_test.shape[0], 
                                     X_test.shape[1]))
## mean centering and normalization:
mean_vals = np.mean(X_train, axis=0)
std_val = np.std(X_train)

X_train_centered = (X_train - mean_vals)/std_val
X_test_centered = (X_test - mean_vals)/std_val

del X_train, X_test

print(X_train_centered.shape, y_train.shape)

print(X_test_centered.shape, y_test.shape)

0 个答案:

没有答案