'Python: Generating random data with bounds

I'm trying to generate random data with lower and upper bounds. I haven't found another way to do define the bounds than lists.

import numpy as np
from scipy.stats import qmc

sampler = qmc.LatinHypercube(d=4)

u_bounds = [2, 10, 10, 2]
l_bounds = [0.1, 0.1, 0.1, 0.1]
data = sampler.lhs_method(100)*(u_bounds-(l_bounds)) + (l_bounds)

This code produces this error

TypeError: unsupported operand type(s) for -: 'list' and 'list'

Any ideas? S.O.S



Solution 1:[1]

Currently, you tried to subbstract two list:

data = sampler.lhs_method(100)*(u_bounds-(l_bounds)) + (l_bounds)

is equal to:

data = sampler.lhs_method(100)*([2, 10, 10, 2] - [0.1, 0.1, 0.1, 0.1]
) + [0.1, 0.1, 0.1, 0.1]

So your error is normal!

I don't really understand what you tried, but if you want to generate random value between two number, try to use:

nb = random.randint(0, 9)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nathan.hoche