0

while extracting the cifar10 dataset im confronted by arrays with the dimension of 32x32x3.

i can plot the image in colour with e.g. plt.imshow(train_data[2]); whats a common way to transform the array to the dimension 32x32 with grayscale values?

train_data, train_labels, test_data, test_labels = 
load_cifar10_data(data_dir)

print(train_data.shape)
print(train_labels.shape)

output:

(50000, 32, 32, 3) (50000,)

meanwhile, i'm just saving the images and read them again, but i guess there is a by far more elegant way to directly store the pictures to grayscale.

hi im vinzent
  • 163
  • 2
  • 15
  • Possible duplicate of [How can I convert an RGB image into grayscale in Python?](https://stackoverflow.com/questions/12201577/how-can-i-convert-an-rgb-image-into-grayscale-in-python) – DJK Oct 07 '17 at 16:43

1 Answers1

-1

You can use your current 3D array to plot a grayscale image using matplotlib's imshow as described here.

import matplotlib.pyplot as plt
plt.imshow(train_data , cmap = "gray")
xssChauhan
  • 2,728
  • 2
  • 25
  • 36