0
$\begingroup$

I need to create random data using this lines

n_samples = 3000

X = np.concatenate((
    np.random.normal((-2, -2), size=(n_samples, 2)),
    np.random.normal((2, 2), size=(n_samples, 2))
))

but didn't get the difference between two lines of random here . I got that this way be used to concatenate two random numbers to create 2 clusters but why one of them using (-2,-2) and the other (2,2) and does 2 in this size because concatenate using to merge 2 groups of random data or not ?

$\endgroup$

1 Answer 1

1
$\begingroup$

Providing multiple values to either the loc or scale arguments can be used to generate multiple random distributions at once with different parameters. In the code you provided the values for the loc argument are the same, meaning that you could also just use the value -2 instead of (-2, -2). You can see this when fixing the seed and generating new numbers

import numpy as np

np.random.seed(0)
print(np.random.normal((-2, -2), size=(5,2)))
# [[-0.23594765 -1.59984279]
#  [-1.02126202  0.2408932 ]
#  [-0.13244201 -2.97727788]
#  [-1.04991158 -2.15135721]
#  [-2.10321885 -1.5894015 ]]

np.random.seed(0)
print(np.random.normal(-2, size=(5,2)))
# [[-0.23594765 -1.59984279]
#  [-1.02126202  0.2408932 ]
#  [-0.13244201 -2.97727788]
#  [-1.04991158 -2.15135721]
#  [-2.10321885 -1.5894015 ]]

The different between the two lines is that one is generating random noise from a normal (Gaussian) distribution with a mean of -2 and the other from a mean of 2, see also the loc keyword in the documentation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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