Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning NumPy Array

You're reading from  Learning NumPy Array

Product type Book
Published in Jun 2014
Publisher
ISBN-13 9781783983902
Pages 164 pages
Edition 1st Edition
Languages
Author (1):
Ivan Idris Ivan Idris
Profile icon Ivan Idris

Table of Contents (14) Chapters

Learning NumPy Array
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Getting Started with NumPy NumPy Basics Basic Data Analysis with NumPy Simple Predictive Analytics with NumPy Signal Processing Techniques Profiling, Debugging, and Testing The Scientific Python Ecosystem Index

Indexing arrays with Booleans


Boolean indexing is indexing based on a Boolean array and falls in the category of fancy indexing. Since Boolean indexing is a form of fancy indexing, the way it works is basically the same. This means that indexing happens with the help of a special iterator object. Perform the following steps to index an array:

  1. First, we create an image with dots on the diagonal. This is in some way similar to the Fancy indexing section. This time we select modulo four points on the diagonal of the image, as shown in the following code snippet:

    def get_indices(size):
       arr = np.arange(size)
       return arr % 4 == 0
  2. Then we just apply this selection and plot the points, as shown in the following code snippet:

    lena1 = lena.copy() 
    xindices = get_indices(lena.shape[0])
    yindices = get_indices(lena.shape[1])
    lena1[xindices, yindices] = 0
    plt.subplot(211)
    plt.imshow(lena1)
  3. Select array values between a quarter and three-quarters of the maximum value, and set them to 0, as shown in the...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}