[Python] Swap two values in a numpy array.

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

  1. Stack

    Stack Membro Participativo

    Is there something more efficient than the following code to swap two values of a numpy 1D array?

    input_seq = arange(64)

    ix1 = randint(len(input_seq))
    ixs2 = randint(len(input_seq))

    temp = input_seq[ix2]
    input_seq[ix2] = input_seq[ix1]
    input_seq[ix1] = temp

    Continue reading...

Compartilhe esta Página