Python Forum
Matrix with bounded random numbers
Thread Rating:
  • 3 Vote(s) - 2.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matrix with bounded random numbers
#1
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.
Reply


Messages In This Thread
Matrix with bounded random numbers - by Felipe - May-19-2017, 11:36 AM
RE: Matrix with bounded random numbers - by zivoni - May-19-2017, 04:57 PM
RE: Matrix with bounded random numbers - by Felipe - May-21-2017, 11:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  fill an empty matrix with random floats sofiapuvogel 2 3,299 Oct-29-2018, 12:33 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020