0
$\begingroup$

I am new to data science and have to generate 200 numbers from a uniform distribution
set this as x and generate y data using x and injecting noise from the gaussian distribution
y = 12x-4 + noise

My Approach:
x = numpy.random.rand(200) --> This will generate 200 numbers form a uniform distribution
I am not sure hot to inject noise from the guassian distribution
probably it's like z = numpy.random.randn(200) and y = 12 * x - 4 + z
Is that a correct way to inject noise?

$\endgroup$
0
$\begingroup$

Yes. numpy.random.randn(n) will generate an array of random numbers (generated by the normal distribution centered at 0) of size n. So just do:

import numpy as np
x = np.random.rand(200)
y = 12 * x - 4 + np.random.rand(200)

Just as you put in your question.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.