Skip to content

real

Returns the real component of a complex number for each element x_i of the input array x.

Parameters:

Name Type Description Default
x

input array of a complex floating-point data type.

required

Returns:

Name Type Description
out array

an array containing the element-wise results. The returned array has a floating-point data type with the same floating-point precision as x (e.g., if x is complex64, the returned array has the floating-point data type float32).

Examples:

>>> a = sparse.COO.from_numpy(np.array([[0 + 1j, 2 + 0j], [0 + 0j, 3 + 1j]]))
>>> o = sparse.real(a)
>>> o.todense()
array([[0., 2.],
       [0., 3.]])
Source code in sparse/numba_backend/_common.py
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
def real(x, /):
    """
    Returns the real component of a complex number for each element ``x_i`` of the input array ``x``.

    Parameters
    ----------
    x: array
        input array of a complex floating-point data type.

    Returns
    -------
    out: array
        an array containing the element-wise results.
        The returned array has a floating-point data type with the same floating-point precision as ``x``
        (e.g., if ``x`` is ``complex64``, the returned array has the floating-point data type ``float32``).

    Examples
    --------
    >>> a = sparse.COO.from_numpy(np.array([[0 + 1j, 2 + 0j], [0 + 0j, 3 + 1j]]))
    >>> o = sparse.real(a)
    >>> o.todense()  # doctest: +NORMALIZE_WHITESPACE
    array([[0., 2.],
           [0., 3.]])
    """
    return x.real