Last active
June 27, 2020 07:01
-
-
Save RuchirChawdhry/953b403a4ea3e662484673e225c1167b to your computer and use it in GitHub Desktop.
Show numpy array as image in Jupyter Notebook (Python 3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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