<p>The type of GAN you used doesn't have any way of controlling which number it generates. For that you would need to train a <a href="https://arxiv.org/abs/1411.1784" rel="nofollow noreferrer">Conditional GAN</a>. </p>

<p>The only means you have to <em>control</em> what images the GAN is generating is through the <strong>noise vector</strong> you input to the generator. What you could try is to change the the values of this vector until you get the digit you want. </p>

<p>The easiest way to do so would be through a random seed</p>

<pre class="lang-py prettyprint-override"><code>np.random.seed(13)  # changing this number will result in different digits being created
noise = np.random.normal(0, 1, size=[examples, random_dim])
generated_images = generator.predict(noise)
generated_images = generated_images.reshape(examples, 28, 28)
</code></pre>
How to control which digit is generated from a GAN trained in MNIST?
<p>I'm interested in GAN so I followed this tutorial <a href="https://www.datacamp.com/community/tutorials/generative-adversarial-networks?fbclid=IwAR1Mq1ePB74ttO6WSnNX4zRrYuUHDBJ39Gwaea5pwjO9x4K-gVPJEdQMLVA" rel="nofollow noreferrer">link</a> about GANs for MNIST with Keras. The result was that it generated a 4x4 image with random digit like <a href="https://i.stack.imgur.com/5yGm8.png" rel="nofollow noreferrer">this</a>. I want to ask how to generate 4x4 image with digit that I want and not random digits like <a href="https://i.stack.imgur.com/Qrtnc.png" rel="nofollow noreferrer">this</a>.</p>

<pre><code>def plot_generated_images(epoch, generator, examples=16, dim=(4, 4), figsize=(4, 4)):
    noise = np.random.normal(0, 1, size=[examples, random_dim])
    generated_images = generator.predict(noise)
    generated_images = generated_images.reshape(examples, 28, 28)

plt.figure(figsize=figsize)

for i in range(generated_images.shape[0]):
    plt.subplot(dim[0], dim[1], i+1)
    plt.imshow(generated_images[i], interpolation='nearest', cmap='gray_r')
    plt.axis('off')

plt.tight_layout()
plt.savefig('gan_generated_image_epoch_%d.png' % epoch)
</code></pre>