Search code examples
pythonvectorizationreshapemovie

Easiest way to flip the dimension of a movie with python


I have a movie, loaded from a tif file using skimage.external.tifffile.imread() into a numpy array with the shape (frames, width, height). What will be the best way to reorder the movie to the shape ( width, height, frames)?

I can build a function that does this using a for loop, but is there a better way to reshape while avoiding a for loop implementation? Some sort of vectorization of the problem?


Solution

  • You can use numpy.moveaxis:

    movie = np.moveaxis(movie, 0, 2)