Skip to main content
`Ctrl`+`K`

# numpy.isreal

numpy.isreal(x)

  Returns a bool array, where True if input element is real.

  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

  `iscomplex`
  `isrealobj`

    Return True if x is not a complex type.

  Notes

  `isreal` may behave unexpectedly for string or object arrays (see examples)

  Examples

      >>> import numpy as np
      >>> a = np.array([1+1j, 1+0j, 4.5, 3, 2, 2j], dtype=np.complex128)
      >>> np.isreal(a)
      array([False,  True,  True,  True,  True, False])

  The function does not work on string arrays.

      >>> a = np.array([2j, "a"], dtype=np.str_)
      >>> np.isreal(a)  # returns the result of `"" == 0` currently.
      array([False, False])

  Returns True for all elements that either have no `.imag` attribute or for which that attribute is zero:

      >>> a = np.array([1, "2", 3+4j], dtype=np.object_)
      >>> np.isreal(a)
      array([ True,  True,  False])