Skip to content

Instantly share code, notes, and snippets.

@nazt
Forked from kylemcdonald/showarray.py
Created October 18, 2019 06:37
Show Gist options
  • Save nazt/8b8b9bdb1161f8677ec54b3bed8284e7 to your computer and use it in GitHub Desktop.
Save nazt/8b8b9bdb1161f8677ec54b3bed8284e7 to your computer and use it in GitHub Desktop.
Minimal code for rendering a numpy array as an image in a Jupyter notebook in memory. Borrowed from the Deep Dream notebook.
import PIL.Image
from cStringIO import StringIO
import IPython.display
import numpy as np
def showarray(a, fmt='png'):
a = np.uint8(a)
f = StringIO()
PIL.Image.fromarray(a).save(f, fmt)
IPython.display.display(IPython.display.Image(data=f.getvalue()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment