I have found the following code:
x=0.3*np.random.randn(100,2)
x_train=np.r_[x 2,x-2]
In the first case x is an array of 100 rows and two columns in a format list of list, for what I see. In this case when I use size it returns 200. However, in the x_train part it is using np.r_. For what I know this instruction serves to concatenate arrays, so when I run size again it returns 400. However, I cannot get what does x 2
and x-2
perform in this case. For example, why in the first case is adding 2 and in the other case is substracting 2?
I have read the documentation and still not get any clue. Any help?
Thanks
CodePudding user response:
The linked scikit is showing how to find two separate classes in 2 dimensions. The code you are asking about generates random x&y coordinate data for those two separate classes
The purpose of np.random.randn
is to generate 100 normally-distributed random x and y coordinate pairs (ie x
is a 100x2 matrix). Side note, the .3 multiplier is probably used to decreased standard deviation for tighter clusters.
By adding 2 to x
(ie add the value 2 to each element in x
), they create a set of x and y coordinates that are closely scattered around (2,2) and by subtracting 2 from x
, they create a set of x and y coordinates that are scattered around (-2,-2).
np.r_
,in this case, is the same as using np.concatenate((x-2,x 2),0)
which creates a 200x2 array with 100 observations of x&y points scattered around (2,2) and 100 scattered around (-2,-2) in one matrix