Skip to content

Cannot access numpy.ndarray.real and imag #2866

@NeilGirdhar

Description

@NeilGirdhar
from typing import Any, Union
import numpy as np
import numpy.typing as npt

ComplexArray = npt.NDArray[Union[np.floating[Any], np.complexfloating[Any, Any]]]

x: ComplexArray = np.array([1j])
print(x.real)  # works great!

def f(x: ComplexArray) -> ComplexArray:
    return x.real  # fails?!

This one's a mystery because it works at the top level, but fails in the function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    as designedNot a bug, working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions