Skip to content

Instantly share code, notes, and snippets.

@Sanlap1997
Created September 24, 2020 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sanlap1997/0b93f0a8844f4ec6b97a5e08115e64bd to your computer and use it in GitHub Desktop.
Save Sanlap1997/0b93f0a8844f4ec6b97a5e08115e64bd to your computer and use it in GitHub Desktop.
# show random images from training set
cols = 8 # Number of columns
rows = 4 # Number of rows
fig = plt.figure(figsize=(2 * cols, 2 * rows))
# Add subplot for each random image
for col in range(cols):
for row in range(rows):
random_index = np.random.randint(0, len(Y_train)) # Pick a random index for sampling the image
ax = fig.add_subplot(rows, cols, col * rows + row + 1) # Add a sub-plot at (row, col)
ax.grid(b=False) # Get rid of the grids
ax.axis("off") # Get rid of the axis
ax.imshow(X_train[random_index, :]) # Show random image
ax.set_title(CIFAR10_CLASSES[Y_train[random_index][0]]) # Set title of the sub-plot
plt.show() # Show the image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment