0

I am using the numpy's random.normal routine to create a Gaussian with a given mean and standard deviation.

array_a = an array of len(100)

gaussian = np.random.normal(loc=array_a,scale=0.1,size=len(2*array_a))

So I expect the gaussian to have a mean=array_a and stddev=0.1 and the size of the gaussian array to be 2 times array_a. However the above returns me an array with the same size as that of array_a !

How do I get the len(gaussian) to be 2 times len(array_a) with the given mean and standard deviation?

Srivatsan
  • 9,225
  • 13
  • 58
  • 83

1 Answers1

1

you have to multiplicate len(array_a) * 2 instead of len(array_a * 2) and loc=array_a.mean() Try:

import numpy as np

array_a = np.arange(100)
gaussian = np.random.normal(loc=array_a.mean(), scale=0.1, size=2 * len(array_a))

Now gaussian.size is 200 and gaussian.mean() is equal to array_a.mean().

Francesco Nazzaro
  • 2,688
  • 11
  • 20
  • I would like the mean to be each value in `array_a`, and not the mean of `array_a`. – Srivatsan Feb 25 '16 at 09:37
  • so you want 100 gaussians as output? – Francesco Nazzaro Feb 25 '16 at 09:39
  • NO!! Each value in `gaussian` will have a different mean. i.e. the first `gaussian` value will have the `mean = first object` of `array_a` and so on. – Srivatsan Feb 25 '16 at 09:40
  • i don't understand. can you explain with a quantitative example what do you expect? – Francesco Nazzaro Feb 25 '16 at 10:01
  • 1
    Actually I now understand! What I wanted was to create a single gaussian array, but with the `mean` being each value of `array_a`. But this is not possible if I want a final array of a size greater than `array_a`. So your method will work, provided I give a single `mean` value. – Srivatsan Feb 25 '16 at 10:03