numpy.isrealobj() in Python (original) (raw)

Last Updated : 07 Aug, 2019

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.

Return :

True, if the input array hasn't any complex element; otherwise False

Code 1 :

import numpy as np

in_array = [ 1 , 3 , 5 , 4 ]

print ( "Input array : " , in_array)

output_value = np.isrealobj(in_array)

print ( "\nIs real : " , output_value)

Output :

Input array : [1, 3, 5, 4]

Is real : True

Code 2 :

import numpy as geek

a = geek.arange( 20 ).reshape( 5 , 4 )

print ( "Is real : " , geek.isrealobj(a))

b = geek.arange( 20 ).reshape( 5 , 4 ).dtype = complex

print ( "\n" ,b)

print ( "\nIs real : " , geek.isrealobj(b))

b = [[ 1j ],

`` [ 3 ]]

print ( "\nIs real : " , geek.isrealobj(b))

Output :

Is real : True

class 'complex'

Is real : True

Is real : False

References :
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.isrealobj.html#numpy.isrealobj
.

Similar Reads