[Python] What is x_train.reshape() and What it Does?

Discussão em 'Python' iniciado por Stack, Março 16, 2025.

  1. Stack

    Stack Membro Participativo

    Using MNIST Dataset

    import numpy as np
    import tensorflow as tf
    from tensorflow.keras.datasets import mnist

    # MNIST dataset parameters
    num_classes = 10 # total classes (0-9 digits)
    num_features = 784 # data features (img shape: 28*28)

    (x_train, y_train), (x_test, y_test) = mnist.load_data()

    # Convert to float32
    x_train, x_test = np.array(x_train, np.float32), np.array(x_test, np.float32)

    # Flatten images to 1-D vector of 784 features (28*28)
    x_train, x_test = x_train.reshape([-1, num_features]), x_test.reshape([-1, num_features])

    # Normalize images value from [0, 255] to [0, 1]
    x_train, x_test = x_train / 255., x_test / 255.


    At the 15th Line of these Code which is,

    x_train, x_test = x_train.reshape([-1, num_features]), x_test.reshape([-1, num_features]). I can't Understand what these reshaping really does in our Dataset..?? Please Explain me.

    Continue reading...

Compartilhe esta Página