I am looking for a way to make a random interpolation between two numpy arrays with few “magical” Numpy operations as possible.
for example, having
a =[1,2,3] b=[4,5,6]
i would like to have as output
c = [ between 1 and 4, between 2 and 5, between 3,6] of integers.
means sort of
def mate_interpolate(arr,arr2): ''' takes 2 parents of same dimention created a child array of same dimention on each place having the element, what value is randomly uniform between the values of parents ''' randfloats = np.random.uniform(0,1,arr.shape) child = arr2 - arr child *= randfloats child += arr #print(randfloats) #child = arr + (arr2 - arr) * randfloats return child
but without creating this additional array and/or with only integers.
For floats, you can just do:
rng = np.random.default_rng() result = rng.uniform(a, b)
If you want integers, you can either truncate, or if
b > a:
result = rng.integers(a, b, endpoint=True)