i have MNIST dataset and i am trying to visualise it using pyplot. The dataset is in cvs
format where each row is one image of 784 pixels. i want to visualise it in
For all like me who want a quick and dirty solution, simply to get a rough idea what a given input is about, in-console and without fancy libraries:
def print_greyscale(pixels, width=28, height=28):
def get_single_greyscale(pixel):
val = 232 + round(pixel * 23)
return '\x1b[48;5;{}m \x1b[0m'.format(int(val))
for l in range(height):
line_pixels = pixels[l * width:(l+1) * width]
print(''.join(get_single_greyscale(p) for p in line_pixels))
(expects the input to be shaped like [784]
and with float values from 0 to 1. If either is not the case, you can easily convert (e.g. pixels = pixels.reshape((784,))
or pixels \= 255
)
The output is a bit distorted but you get the idea.