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.

Audiogott
  • 95
  • 2
  • 12
  • 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`. – user2653663 Sep 05 '19 at 10:03
  • 1
    That was perfect. If you post it as an answer, I will accept it. Thank you! – Audiogott Sep 05 '19 at 10:09

1 Answers1

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
user2653663
  • 2,818
  • 1
  • 18
  • 22