[Python] Quickest way to compute the sum of squared elements of the result of a matrix...

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024.

  1. Stack

    Stack Membro Participativo

    I want to do something like this in Python

    sum(square(matmul(A, B)))


    There are various ways you can achieve this behavior, e.g.,

    sum(np.square(np.matmul(A, B)))


    or

    np.lingalg.norm(np.matmul(A, B)) ** 2


    I haven't profiled it yet, but I suspect the second option will be faster (less ops, fused operations, etc.).

    Are there other approaches that could potentially beat this? I'd like to profile various approaches to solving this. I'm not restricted to numpy.

    Continue reading...

Compartilhe esta Página