[Python] Is there a way to compute only the real part of a NumPy matmul?

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    Let's say I have two arrays a and b both with dtype np.complex128 and I want to compute C = np.matmul(a, b).real .

    That is, I don't care about the imaginary part, only the real part. Is there a better way to do this? It seems like such a method would provide a decent speedup considering that only around half of the floating point multiplications are actually required.

    As a bonus question, what I actually want to do is compute the real part of the einsum np.einsum("ab,bc,cd,da->a", ...).real with rather large operands, so hopefully methods for the basic question are generalizable to einsum.

    Continue reading...

Compartilhe esta Página