O'Reilly logo

NumPy Cookbook - Second Edition by Ivan Idris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Flipping Lena

We will be flipping the SciPy Lena image—all in the name of science, of course, or at least as a demo. In addition to flipping the image, we will slice it and apply a mask to it.

How to do it...

The steps are as follows:

  1. Flip the Lena array around the vertical axis using the following code:
    plt.imshow(lena[:,::-1])
    
  2. Take a slice out of the image and plot it. In this step, we will take a look at the shape of the Lena array. The shape is a tuple representing the dimensions of the array. The following code effectively selects the top-left quadrant of the Playboy picture:
    plt.imshow(lena[:lena.shape[0]/2,:lena.shape[1]/2])
    
  3. Apply a mask to the image by finding all the values in the Lena array that are even (this is just arbitrary for demo purposes). ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required