Skip to content

Instantly share code, notes, and snippets.

@uduse
Forked from zori/showarray.py
Last active November 27, 2017 15:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uduse/e3122b708a8871dfe9643908e6ef5c54 to your computer and use it in GitHub Desktop.
Save uduse/e3122b708a8871dfe9643908e6ef5c54 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. Forked and updated for Python 3.
import PIL.Image
from io import BytesIO
import IPython.display
import numpy as np
def show_array(a, fmt='png'):
f = BytesIO()
PIL.Image.fromarray(np.uint8(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