Balázs Fehér
Balázs Fehér

Reputation: 344

How to create numpy ndarray from numpy ndarrays?

I used the MNIST dataset for training a neural network, where the training data is returned as a tuple with two entries. The first entry contains the actual training images. This is a numpy ndarray with 50,000 entries. Each entry is, in turn, a numpy ndarray with 784 values, representing the 28 * 28 = 784 pixels in a single MNIST image.

I would like to create a new training set, however I do not know how to create an ndarray from other ndarrays. For instance, if I have the following two ndarrays:

a = np.ndarray((3,1), buffer=np.array([0.9,1.0,1.0]), dtype=float)

b = np.ndarray((3,1), buffer=np.array([0.8,1.0,1.0]), dtype=float)

how to make a third one containing these two?

I tried the following but it creates only one entry.

c = np.ndarray((1,6,1), buffer=np.array(([a],[b])), dtype=float)

I would need it to be two entries.

Upvotes: 2

Views: 3054

Answers (1)

Balázs Fehér
Balázs Fehér

Reputation: 344

Thanks, in the meanwhile I figured out it is simply:

c = np.array((a, b))

Upvotes: 3

Related Questions