Skip to content

Instantly share code, notes, and snippets.

@RuchirChawdhry
Last active June 27, 2020 07:01
Show Gist options
  • Save RuchirChawdhry/953b403a4ea3e662484673e225c1167b to your computer and use it in GitHub Desktop.
Save RuchirChawdhry/953b403a4ea3e662484673e225c1167b to your computer and use it in GitHub Desktop.
Show numpy array as image in Jupyter Notebook (Python 3)
import numpy as np
from PIL import Image
from IPython import display
from io import BytesIO
def show_array(arr, fmt="png"):
arr = np.uint8(arr)
f = BytesIO()
Image.fromarray(arr).save(f, fmt)
display.display(
display.Image(
data=f.getvalue()
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment