0% found this document useful (0 votes)
3 views2 pages

NumPy Searching Arrays Lab

The document consists of a series of lab questions focused on using NumPy functions such as np.where(), np.searchsorted(), and np.nonzero() for searching and filtering arrays. It includes tasks like finding indices of specific values, locating even numbers, and filtering based on conditions. Additionally, it encourages user interaction by prompting for input to demonstrate these functions in practical scenarios.

Uploaded by

jeevavaishnavi7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

NumPy Searching Arrays Lab

The document consists of a series of lab questions focused on using NumPy functions such as np.where(), np.searchsorted(), and np.nonzero() for searching and filtering arrays. It includes tasks like finding indices of specific values, locating even numbers, and filtering based on conditions. Additionally, it encourages user interaction by prompting for input to demonstrate these functions in practical scenarios.

Uploaded by

jeevavaishnavi7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

NumPy Searching Arrays – Lab Questions

1. Using where()
1. Write a program to find all indices of the number 5 in the array [1, 5, 3, 7,
5, 9, 5].
2. Create an array of numbers 1–20. Use [Link]() to find all even
numbers.
3. From the array [10, 20, 30, 40, 50], use [Link]() to find elements
greater than 25.
4. Given [2, 4, 6, 8, 10, 12], use [Link]() to check where numbers are
divisible by 4.
5. Create a program where the user enters a number and you use [Link]()
to find its index inside an array.

2. Using searchsorted()
6. Use [Link]() to find where the value 25 should be inserted in [10,
20, 30, 40, 50].
7. Try inserting multiple values [15, 35] into [10, 20, 30, 40, 50] and print the
positions.
8. Use [Link]() with side='right' to find the index of 30 in [10, 20,
30, 30, 40].
9. Write a program that asks the user to input a number and tells at which
index it should be inserted in [1,3,5,7,9].
[Link] how searchsorted() behaves with a descending array. Example:
[100, 90, 80, 70].

3. Using [Link]()
[Link] an array [0, 2, 0, 4, 5, 0, 7]. Use [Link]() to find all non-zero
indices.
[Link] the indices of numbers greater than 50 in [10, 55, 67, 32, 99] using
nonzero().
[Link] [Link]() on [1, 3, 5, 7, 9] to find where numbers are greater
than 4.
[Link] a program that generates an array of random integers (size 10). Use
[Link]() to find all numbers divisible by 3.
[Link] [Link]() to locate negative numbers in [10, -2, -5, 8, -7, 12].

4. Filter Arrays (Boolean Indexing)


[Link] a filter that selects only even numbers from [1,2,3,4,5,6,7,8].
[Link] a filter to extract values greater than 100 from [50, 120, 180, 90,
200].
[Link] [2, 4, 6, 8, 10], filter numbers that are not divisible by 4.
[Link] a filter that selects only negative numbers from [-5, -2, 0, 4, -7, 9].
[Link] a program where the user inputs a threshold, and filter all numbers
greater than that threshold from [10, 20, 30, 40, 50].

You might also like