Real Python

How to Use Conditional Expressions With NumPy where()

This tutorial teaches you how to use the where() function to select elements from your NumPy arrays based on a condition. You'll learn how to perform various operations on those elements and even replace them with elements from a separate array or arrays.