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] How to do batched matrix vector multiplication with np.matvec

Discussão em 'Python' iniciado por Stack, Setembro 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have rotation matrix, for the sake of a simple example, np.ndarray(..., shape=(3, 2)), and I want to multiply it by an nd-array of vectors, say np.mgrid[:4, :5], how do I do that with the new np.matvec function? I guess the signature I want from this generalized ufunc is (3, 2), (2, 4, 5) -> (3, 4, 5). I would expect that I need to use the axes command to make the matrices line up, however I am not sure what the syntax is. When I try something based on intuition, I get an error:

    ValueError: axes should be a list with an entry for all 3 inputs and outputs; entries for outputs can only be omitted if none of them has core axes.

    I have no idea what this means, and the documentation for np.matvec doesn't have any examples or information on how to use the axis or axes keywords. How do I do this correctly?

    Continue reading...

Compartilhe esta Página