[Python] np.random.shuffle() with seed giving different shuffles every time

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have a lengthy list that stores ~127k integers. I want to shuffle the list with a seed for reproducible results later on. However, it seems as though every time I execute the code, the list gets re-shuffled. This is the code:

    import numpy as np
    np.random.seed(5)
    np.random.shuffle(labels)
    print(labels[:5])


    The print statement at the end gives different results on each run, e.g.:

    [124802, 178520, 155245, 127235, 146541]
    [31595, 120382, 47991, 141687, 62795]
    [13991, 67563, 69090, 76243, 184231]


    I apologize if I'm overseeing something very obvious. Hopefully someone can take a few mins out of their time to help!

    Cheers!

    Continue reading...

Compartilhe esta Página