[Python] How to repeatedly sample so that the sampling result doesn't change?

Discussão em 'Python' iniciado por Stack, Junho 27, 2025.

  1. Stack

    Stack Membro Participativo

    I have an array from which I want to select a number of rows, so that the rows selected don't vary if I repeat the sampling process.

    In my following code, this is not the case; each time I run the selecting process, I get a different array:

    points
    array([[ 4.926, 46.153],
    [ 5.428, 46.009],
    [ 5.373, 45.961],
    ...,
    [ 2.404, 49.008],
    [ 2.387, 49.074],
    [ 1.825, 49.096]], shape=(34806, 2))
    sel = np.random.choice(points.shape[0], size=6, replace=False)
    points_sampled = points[sel]
    points_sampled
    array([[ 1.862, 48.238],
    [ 5.984, 46.951],
    [ 4.838, 47.172],
    [ 7.082, 49.022],
    [ 3.39 , 50.299],
    [ 3.099, 50.318]])


    What would be the simplest way to achieve this?

    Continue reading...

Compartilhe esta Página