- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to print array elements within a given range using Numpy?
In this program, we have to print elements of a numpy array in a given range. The different numpy functions used are numpy.where() and numpy.logical_and().
Step 1: Define a numpy array. Step 2: Use np.where() and np.logical_and() to find the numbers within the given range. Step 3: Print the result.
import numpy as np arr = np.array([1,3,5,7,10,2,4,6,8,10,36]) print("Original Array:\n",arr) result = np.where(np.logical_and(arr>=4, arr<=20)) print(result)
Original Array: [ 1 3 5 7 10 2 4 6 8 10 36] (array([2, 3, 4, 6, 7, 8, 9], dtype=int64),)
The result gives the index positions of elements which satisfy the condition in the np.where() function.
- How to create a numpy array within a given range?
- Golang Program to Print Odd Numbers Within a Given Range
- Find elements within range in numpy in Python
- How to find Kaprekar numbers within a given range using Python?
- Python Program to replace list elements within a range with a given number
- Mask array elements equal to a given value in Numpy
- Mask array elements not equal to a given value in Numpy
- Print prime numbers in a given range using C++ STL
- Program to print prime numbers in a given range using C++ STL
- Java Program to create random BigInteger within a given range
- Constrain a number within a given range in Arduino
- Mask array elements greater than a given value in Numpy
- Mask array elements less than a given value in Numpy
- How to find the sum of all elements of a given matrix using Numpy?
- Python program to print all distinct elements of a given integer array.