Vijay Kalmath
Vijay Kalmath

Reputation: 178

Using numpy.append to mutate array

I am working on tensorflow with MNIST database.

After extracting the database using the input_data.read_data_sets Function,

from tensorflow.examples.tutorials.mnist import input_data
data = input_data.read_data_sets('data/MNIST/', one_hot=True)

I get data.train.images which is an array containing arrays of images.

I want to add my own image array onto this, as they are numpy arrays I cannot use the standard append function.

When I use the numpy.append() function, it creates a new array rather than mutate the existing one.

data.test.images is array of 55000 arrays each of 784(float32)values,

A is an array of 784(float32)values

The problem is when I try

data.train.images=np.append(data.train.images, [A],axis=0)

I get the error saying: " can't set attribute "

How do I get through this conundrum?

Upvotes: 1

Views: 570

Answers (1)

skrubber
skrubber

Reputation: 1095

Use numpy + vstack instead:

a=np.array(np.random.rand(20,10))
b=np.array(np.random.rand(1,10))
a.shape
(20,10)
a=np.vstack([a,b])
a.shape
(21, 10)

Upvotes: 1

Related Questions