Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a uniformly random matrix in Julia?

l want to get a matrix with uniformly random values sampled from [-1,2]

x= rand([-1,2],(3,3))
3x3 Array{Int64,2}:
 -1  -1  -1
  2  -1  -1
 -1  -1  -1

but it takes into consideration just -1 and 2, and I'm looking for continuous values for instance -0.9 , 0.75, -0.09, 1.80. How can I do that?

like image 853
vincet Avatar asked Aug 22 '16 15:08

vincet


1 Answers

Note: I am assuming here that you're looking for uniform random variables.

You can also use the Distributions package:

## Pkg.add("Distributions") # If you don't already have it installed.
using Distributions
rand(Uniform(-1,2), 3,3)

I do quite like isebarn's solution though, as it gets you thinking about the actual properties of the underlying probability distributions.

like image 146
Michael Ohlrogge Avatar answered Oct 10 '22 18:10

Michael Ohlrogge