AI engineering glossary · NumPy pandas visualization

What is np.where?

np.where: A NumPy function that chooses between two values for each element depending on a condition array. With one argument only, it instead returns the positions where the condition is true. It is a vectorised replacement for an if-else inside a loop.

Level: intermediateTopic: NumPy pandas visualization

np.where: an example

np.where(marks >= 40, 'pass', 'fail') labels every mark in an array as pass or fail in one step.

Related terms

More NumPy pandas visualization terms

Where you learn it

np.where is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.