Last active
October 11, 2021 15:59
-
-
Save cwindolf/a160717692c790c93a230f728533c4c4 to your computer and use it in GitHub Desktop.
Quickly animate numpy arrays in Jupyter
This file contains hidden or 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 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