Return vector when broadcasting over mean vector to generate random numbers

Hi there,

I am wanting to use something like

rand.(Normal.([5;10],1),1)

where we have two different mean values \mu_1=5, \mu_2=10 which we broadcast over to generate 2 random numbers total. I would like the output to be a 2-element vector, where each element of the vector is a float64, but instead it returns a 2-element vector, which each element being a 1-element vector.

Example of current output:

2-element Vector{Vector{Float64}}:
 [5.660588027201526]
 [10.557198737804264]

Thanks in advance.

rand(<distribution>) creates a single random value, whereas rand(<distribution>, 1) creates a 1-vector of random values. Therefore, you just have to remove the last argument of the broadcasted rand:

rand.(Normal.([5;10],1))
2 Likes

Brilliant, thanks!