Skip to content

Instantly share code, notes, and snippets.

@rueberger
Created June 6, 2017 20:49
Show Gist options
  • Save rueberger/4910b53a0e0c95c03f1db4324bfcbb55 to your computer and use it in GitHub Desktop.
Save rueberger/4910b53a0e0c95c03f1db4324bfcbb55 to your computer and use it in GitHub Desktop.
render array as image in jupyter - python 3
import PIL.Image
from io import BytesIO
import IPython.display
import numpy as np
def showarray(a, fmt='png'):
a = np.uint8(((a - np.min(a)) / np.max(a)) * 255)
f = BytesIO()
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