numpy.real — NumPy v2.6.dev0 Manual

numpy.real(val)

[source]

#

Return the real part of the complex argument.

Parameters:valarray_likeInput array.

Returns:outndarray or scalarThe real component of the complex argument. If val is real, the type of val is used for the output. If val has complex elements, the returned type is float.

Examples

>>> importnumpyasnp>>> a=np.array([1+2j,3+4j,5+6j])>>> a.realarray([1., 3., 5.])>>> a.real=9>>> aarray([9.+2.j, 9.+4.j, 9.+6.j])>>> a.real=np.array([9,8,7])>>> aarray([9.+2.j, 8.+4.j, 7.+6.j])>>> np.real(1+1j)1.0