human
I am working on the file "Seminar3/outdated/Seminar 3.ipynb".
The first task is:
Now we define a bunch of helper functions for interpolation visualization. Note the diplay_manifold_flythrough function. First two arguments are array of images and their coordinates on the 2D plane.
Can you write Python program for it?
assistant
#Here is the Python program you requested.

from IPython.display import HTML
from matplotlib import animation

VIDEO_TAG = """<video controls>
 <source src="data:video/x-m4v;base64,{0}" type="video/mp4">
 Your browser does not support the video tag.
</video>"""

def anim_to_html(anim):
    if not hasattr(anim, '_encoded_video'):
        with open('temp.mp4', 'wb') as f:
            anim.save(f.name, fps=20, extra_args=['-vcodec', 'libx264'], writer='ffmpeg')
            video = open('temp.mp4', "rb").read()
        anim._encoded_video = video.encode("base64")
    
    return VIDEO_TAG.format(anim._encoded_video)

def display_animation(anim):
    plt.close(anim._fig)
    return HTML(anim_to_html(anim))

def diplay_manifold_flythrough(X, coords, fig, ax):
    imagebox = OffsetImage(X[0].reshape(28, 28), cmap=plt.cm.gray_r)
    annbox = AnnotationBbox(imagebox, coords[0])
    ax.add_artist(annbox)

    def init():
        return imagebox, annbox

    def animate(i):
        imagebox.set_data(X[i].reshape(28, 28))
        annbox.xyann = coords[i]

        return imagebox, annbox

    anim = animation.FuncAnimation(fig, animate, init_func=init, frames=X.shape[0], interval=20, blit=True)

    return display_animation(anim)