samedi 18 novembre 2017

Randomly sample sub-arrays from a 2D array in python

Problem:

Let's say I have a 2D array from which I want to randomly sample (using Monte-Carlo) smaller 2D sub-arrays as shown by the black patches in the figure below. I am looking for an efficient method of doing this.

enter image description here

Prospective (but partial) solution:

I came across one function that partially achieves what I am trying to do after several hours of search, but it lacks the ability to sample a patch at a random location. At least I don't think it can sample from random locations based on its arguments, although it does have one random_state argument that I do not understand.

sklearn.feature_extraction.image.extract_patches_2d(image, patch_size, max_patches=None, random_state=None)




Aucun commentaire:

Enregistrer un commentaire