Was ist x_train.reshape () und was macht es?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Was ist x_train.reshape () und was macht es?

by Anonymous » 16 Mar 2025, 15:28

Verwenden von MNIST -Datensatz < /p>

Code: Select all

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.
< /code>

In der 15. Zeile < /strong> dieser Code, < /p>

x_train, x_test = x_train.reshape([-1, num_features]), x_test.reshape([-1, num_features])
. Ich kann nicht verstehen, was diese Umgestaltung in unserem Datensatz wirklich tut. Bitte erklären Sie mich.

Top