[Python] diagonalize multiple vectors using numpy

Discussão em 'Python' iniciado por Stack, Janeiro 31, 2025.

  1. Stack

    Stack Membro Participativo

    Say I have a matrix of shape (2,3), I need to diagonalize the 3-elements vector into matrix of shape (3,3), for all the 2 vectors at once. That is, I need to return matrix with shape (2,3,3). How can I do that with Numpy elegantly ?

    given data = np.array([[1,2,3],[4,5,6]])

    i want the result [[[1,0,0],
    [0,2,0],
    [0,0,3]],

    [[4,0,0],
    [0,5,0],
    [0,0,6]]]



    Thanks

    Continue reading...

Compartilhe esta Página