Sitemap

Member-only story

Searching in Numpy Array

4 min readJun 30, 2026

--

What is Array Search?

Sometimes we need to find a specific value or check a condition inside an array.

For example:

  • Find where 25 is present.
  • Find all even numbers.
  • Find all odd numbers.
  • Find the correct position to insert a value into a sorted array.

NumPy provides different functions to perform these searching tasks.

1. np.where()

Description

np.where() is used to search an array based on a condition.

Instead of returning the values, it returns the indexes where the condition becomes True.

Syntax

np.where(condition)

The condition can be:

  • ==
  • >
  • <
  • >=
  • <=
  • %

Example 1: Find the index of a value

import numpy as np
arr = np.array([12, 25, 18, 25, 30, 25])result = np.where(arr == 25)print(result)

Output

(array([1, 3, 5]),)

Explanation

--

--

Md Dilshad Hassan
Md Dilshad Hassan

Written by Md Dilshad Hassan

I am a computer science enthusiast. I am aspire to write the contents about technologies related to computer science.