1

current situation of x_train array

I have x_train array which is of 235 elements and each element is a numpy array of rows 125 and 125 columns . I neeed this array to be in shape of (235,125,125) so as to feed to my convolutional neural network model ((((similar to case when we need to feed MNIST digit array of (6000,28,28) where we have 60000 samples each of which is 28x28 array)))

Can someone tell how to reshape the x_train array to (235,125,125) ?

P.S I initially converted x_train from pandas series to numpy array below is the snapshot

2 Answers 2

1

You need to use Numpy's reshape command:

x_train = x_train.reshape(x_train.shape[0], 125, 125, 1)

Have a look at this part of Keras' MNIST CNN tutorial.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use the np.newaxis as follows:

x_train [...,np.newaxis]

And you will the shape will be:

x_train [...,np.newaxis].shape
(235, 125, 125, 1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.