mardi 24 novembre 2020

How to generate a random numpy array, but with a certain criterion, for example that each element is greater than the previous one?

I was wondering if there's a neat way to generate a random array in Python (naturally, using numpy) with a certain given structure, for instance an array of random ints where each element in the array is greater than the previous one: For instance, a and b would satisfy the criterion, but c wouldn't:

a = [1, 2, 3, 4, 5, 6, 7, 8]
b = [10, 22, 57, 154]
c = [5, 12, 75, 44, 66]

Similarly, is there a systematic way to set any similar sort of criteria, for instance to have a random array where the elements first increase and then, after a certain point, they start to decrease. Or would these situations require different approach every time?

Thanks!




Aucun commentaire:

Enregistrer un commentaire