flopscope.numpy.isreal
fnp.isreal(x)[flopscope source][numpy source]
Returns a bool array, where True if input element is real.
Adapted from NumPy docs np.isreal
Cost
Flopscope Context
Test if element is real (imag == 0) element-wise.
If element has complex type with zero imaginary part, the return value for that element is True.
Parameters
- x:array_like
Input array.
Returns
- out:ndarray, bool
Boolean array of same shape as
x.
See also
- we.flops.iscomplex
- we.flops.isrealobj Return True if x is not a complex type.
Notes
isreal may behave unexpectedly for string or object arrays (see examples)
Examples
>>> import flopscope.numpy as fnp
>>> a = flops.array([1+1j, 1+0j, 4.5, 3, 2, 2j], dtype=complex)
>>> flops.isreal(a)
array([False, True, True, True, True, False])The function does not work on string arrays.
>>> a = flops.array([2j, "a"], dtype="U")
>>> flops.isreal(a) # Warns about non-elementwise comparison
FalseReturns True for all elements in input array of dtype=object even if
any of the elements is complex.
>>> a = flops.array([1, "2", 3+4j], dtype=object)
>>> flops.isreal(a)
array([ True, True, True])isreal should not be used with object arrays
>>> a = flops.array([1+2j, 2+1j], dtype=object)
>>> flops.isreal(a)
array([ True, True])