1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Numpy handling small imaginary parts differently

Discussão em 'Python' iniciado por Stack, Novembro 25, 2025.

  1. Stack

    Stack Membro Participativo

    There is a difference in behaviour on macOS with arm64 CPU vs other Linux with amd64.

    For numpy v1 on arm64, it seems there is an internal logic guaranteeing the imaginary part to be exactly 0:

    >>> import numpy as np
    >>> np.__version__
    '1.26.4'
    >>> x = 0.1 + 0.2j
    >>> x * np.conj(x)
    (0.05000000000000001+0j)


    For v2 on arm64, this check is disabled and the imaginary part fluctuated at the border of double precision as expected:

    >>> import numpy as np
    >>> np.__version__
    '2.3.5'
    >>> x = 0.1 + 0.2j
    >>> x * np.conj(x)
    np.complex128(0.05000000000000001+1.6653345369377347e-18j)


    For v1 & v2 on amd64, the check seems to be enabled and the imaginary part is 0 exactly.

    Is there a native way to re-enable this check on macosx-arm64 and obtain results with the imaginary part equal to 0?

    Continue reading...

Compartilhe esta Página