dimanche 12 novembre 2017

How do you pick a random index in an array with replacement using sklearn?

I'm trying to use sklearn.util.resample in order to choose randomly from an array of 10,000 images. Everytime I go through the list, I want to to choose one of those images, then pick a random number for that (already did that) and when I do use it, I want to remove it so I don't use it again.

My current code:

def displaySample(N, D):
    i = 0
    plt.figure()
    plt.suptitle("test")
    bounds = int(math.ceil(int(np.sqrt(N))))
    while i < N:
        plt.subplot(bounds, bounds, i + 1)
        plt.axis('off')
        disp = D[random.randint(0,9)]
        squareR = int(np.sqrt(disp.shape[1]))
        temp = disp[random.randint(0, len(D))].reshape(squareR, squareR) ## HERE
        plt.imshow(temp, cmap='Greys', interpolation='nearest')
        i += 1
    plt.show()

I pointed out where I want to do this, I want to replace random.randint(0, len(D)) so I don't repick it. I think I'm supposed to use the argument replace=false but I couldn't find any examples of its usage so I don't know how to go about it.




Aucun commentaire:

Enregistrer un commentaire