Skip to content

Instantly share code, notes, and snippets.

@cwindolf
Last active October 11, 2021 15:59
Show Gist options
  • Save cwindolf/a160717692c790c93a230f728533c4c4 to your computer and use it in GitHub Desktop.
Save cwindolf/a160717692c790c93a230f728533c4c4 to your computer and use it in GitHub Desktop.
Quickly animate numpy arrays in Jupyter
import tempfile
import imageio
from IPython.display import Image
def ipygif(z, fps=16, width=200, height=200):
f = tempfile.NamedTemporaryFile(prefix="ipygif", suffix=".gif")
z = z - z.min()
z *= 255.0 / z.max()
imageio.mimwrite(f.name, z.astype(np.uint8), fps=fps)
return Image(filename=f.name, embed=True, width=width, height=height)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment