1

I manipulated the MNIST dataset for research, by adding a set of digits to each digit in the dataset.

Before manipulation:

In:
x_train.shape

Out: 
(60000, 28, 28)

Expectated result after manipulation:

In:
x_train_new.shape

Out: 
(60000, 11, 28, 28)

However I messed up and forgot to add x_train[i] in each iteration. Therefore my shape is the following:

In:
x_train_new.shape

Out: 
(60000, 10, 28, 28)

I have tried to apply np.insert, however I am struggling to apply it correctly since it is a multidimensional array:

tryout = x_train_new[0]

In:
np.insert(tryout, 0, x_train[0])

Out:
ValueError: could not broadcast input array from shape (28,28) into shape (28)

How can I insert x_train[i] to each ``ì```? Is it possible to insert the array as the first value in each array?

Any help is appreciated. Thank you very much.

2
  • 1
    Just create an empty array x_train_expected = np.empty((60000, 11, 28, 28)) and do x_train_expected[:,1:] = x_train_new followed by x_train_expected[:,0] = x_train. Commented Sep 5, 2019 at 10:03
  • 1
    That was perfect. If you post it as an answer, I will accept it. Thank you! Commented Sep 5, 2019 at 10:09

1 Answer 1

1

Just create an empty array

x_train_expected = np.empty((60000, 11, 28, 28))

and do

x_train_expected[:,1:] = x_train_new
x_train_expected[:,0] = x_train
Sign up to request clarification or add additional context in comments.

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.