lundi 7 mars 2016

Replace values in a 2D array with different random numbers

I have a 2D array (image) in which I want to replace array values greater than some threshold with a random number in some range. My attempt was to use numpy.random.uniform, as so

Z[Z > some_value] = uniform(lower_limit,upper_limit)

However I've found that this replaces all values above the threshold with the same random value. I would like to replace all array values above the threshold with a different random value each.

I think this would require some interation over the entire array for which I would need to generate a random value if the condition is met. How would I do this?




Aucun commentaire:

Enregistrer un commentaire