Python Forum

Full Version: Matrix with bounded random numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone, 

I want to construct a matrix with aleatory numbers that are limited by previously determined values. These values are gave in arrays which contains the upper (ub) and lower bounds (lb). I know how to create a vector/array with these characteristics, like the code below shows:

import numpy as np
from random import random

lb = np.array([1,2,3,4])
ub = np.array([5,6,7,8])

example = lb+(ub-lb)*random()
Here's an output from the code above:
Output:
[ 4.63529552  5.63529552  6.63529552  7.63529552]
Now, what's the fastest "pythonic" way to construct a matrix (4,4), which the values are limited by the upper and lower bounds? 
Here's an example of desired output using the same bounds of the code above:
Output:
[ 4.63529552  5.63529552  6.63529552  7.63529552] [ 3.53452228  4.53452228  5.53452228  6.53452228] [ 1.43902942  2.43902942  3.43902942  4.43902942] [ 2.70643708  3.70643708  4.70643708  5.70643708]
Thanks for the help.
lb + (ub - lb) * np.random.random((4, 1))
if you want for each row inequalities (lb <= row) & (row < ub)
(May-19-2017, 04:57 PM)zivoni Wrote: [ -> ]
lb + (ub - lb) * np.random.random((4, 1))
if you want for each row inequalities (lb <= row) & (row < ub)

Thanks !!! That solved my problem.