Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
numpy.isreal() in Python
Next article icon

numpy.isreal() in Python

Last Updated : 21 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

numpy.isreal() tests element-wise whether each value in the input array is a real number (i.e., not complex). It returns a Boolean result as a boolean array. Example:

Python
import numpy as np a = np.array([1+0j, 2+3j, 5, 4.5, 7j]) res = np.isreal(a) print(res) 

Output
[ True False  True  True False] 

Explanation: np.isreal() returns True for real numbers (even if written with +0j) and False for complex numbers with a non-zero imaginary part like 2+3j or 7j.

Syntax

numpy.isreal(x)]

Parameters: x is the input array or scalar (can be complex).

Returns: A Boolean array of the same shape as x.

  • Returns True for elements that are real.
  • Returns False for elements that have a non-zero imaginary part.

Examples

Example 1: In this example, we use np.isreal() with a purely real-valued array.

Python
import numpy as np a = np.array([1, 2.5, 0, -3]) res = np.isreal(a) print(res) 

Output
[ True  True  True  True] 

Explanation: All elements in the array are real numbers, so np.isreal() returns True for each one.

Example 2: In this example, we use a 2D array with both real and complex values to check element-wise real status.

Python
import numpy as np a = np.array([[1+0j, 3+4j], [5, 0-2j]]) res = np.isreal(a) print(res) 

Output
[[ True False]  [ True False]] 

Explanation:

  • 1+0j and 5 are real, so they return True.
  • 3+4j and 0-2j have imaginary parts, so they return False.

Example 3: In this example, we filter out only real values from an array that includes complex numbers.

Python
import numpy as np a = np.array([2+0j, 3+1j, 4, 5-2j]) res = a[np.isreal(a)] print(res) 

Output
[2.+0.j 4.+0.j] 

Explanation: We use the Boolean mask returned by np.isreal() to extract only the real values from the array. Complex numbers are excluded.


Next Article
numpy.isreal() in Python

M

Mohit Gupta_OMG
Improve
Article Tags :
  • Python
  • Python-numpy
  • Python numpy-Logic Functions
Practice Tags :
  • python

Similar Reads

    numpy.isrealobj() in Python
    numpy.isrealobj(array) : This logical function helps to checks if the array has no complex type or array has a complex number. Even if imaginary part is equal to zero, it is not considered to be a Real Object. Parameters : array : [array_like]Input array or object whose elements, we need to test. Re
    2 min read
    numpy.isnan() in Python
    The numpy.isnan() function tests element-wise whether it is NaN or not and returns the result as a boolean array. Syntax :  numpy.isnan(array [, out]) Parameters :  array : [array_like]Input array or object whose elements, we need to test for infinity out : [ndarray, optional]Output array placed wit
    2 min read
    numpy.isscalar() in Python
    In this article, we will elucidate the `numpy.isscalar()` function through a well-documented code example and comprehensive explanation. Python numpy.isscalar() Syntax Syntax : numpy.isscalar(element) Parameters: element: The input element to be checked for scalar properties.Return Type: bool: Retur
    3 min read
    numpy.isinf() in Python
    numpy.isinf() test element-wise whether a value is positive or negative infinity. It returns a Boolean array with True where the input is either +inf or -inf and False otherwise. Example:Pythonimport numpy as np a = np.array([1, np.inf, -np.inf, 0, np.nan]) res = np.isinf(a) print(res)Output[False T
    2 min read
    numpy.isneginf() in Python
    The numpy.isneginf() function tests element-wise whether it is negative infinity or not, and returns the result as a boolean array. Syntax :   numpy.isneginf(array, y = None) Parameters :  array : [array_like]Input array or object whose elements, we need to test for infinity. y : [array_like]A boole
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences