[Python] How to swap the rows of a numpy array

Discussão em 'Python' iniciado por Stack, Março 4, 2025.

  1. Stack

    Stack Membro Participativo

    I tried implementing a function to swap the rows of a numpy array, but it does not seem to work

    This is the code:

    def SwapRows(M: np.ndarray, row_num_1: int, row_num_2: int) -> np.ndarray:
    M_copy = M.copy()
    # exchange row 1 and row 2
    temp = M_copy[row_num_1]
    M_copy[row_num_1] = M_copy[row_num_2]
    M_copy[row_num_2] = temp # I dont know why this method does not seem to work

    return M_copy


    any ideas as to why?

    Continue reading...

Compartilhe esta Página