From the course: More Python Tips, Tricks, and Techniques for Data Science
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Comparison, masks, and Boolean logic - Python Tutorial
From the course: More Python Tips, Tricks, and Techniques for Data Science
Comparison, masks, and Boolean logic
- [Instructor] In this video, we're going to understand Boolean operations and NumPy arrays. We'll be covering how to use comparison operators as element-wise universal functions. We'll see how to use Boolean arrays with composite conditions, and at last we'll see how to filter values using masking. First off again, let's import the NumPy package. Here I have created an array with 10, 20, 30, 40, 50. Now, if I want to see or check which array values are greater than 20 let's say, I can do this. I can do arr, array, greater than equal to 20, and this will check on each of the element of my array, if their value is greater than 20 or not. You see? It returns a Boolean array, which tells me that if that particular element was greater than equal to 20 or not. I got true for all the values that are greater than or equal to 20. Similarly, I can use use any of the comparison operator, equal to equal to, greater than equal to,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.