Generating data points

Now, we define a function called sample_points for generating our input (x, y) pairs. It takes the parameter k as input, which implies the number of (x, y) pairs we want to sample:

def sample_points(k):
x = np.random.rand(k,50)
y = np.random.choice([0, 1], size=k, p=[.5, .5]).reshape([-1,1])
return x,y

The preceding function returns output as follows:

x, y = sample_points(10)
print x[0]
print y[0]

[5.01913307e-01 1.01874941e-01 7.16678998e-01 3.90294047e-01
2.95330904e-01 8.66751993e-01 5.09988127e-01 8.59389493e-01
5.16202142e-01 7.92016358e-01 8.24237307e-01 7.76739141e-01
8.57034917e-01 2.75862141e-01 6.44874856e-01 2.75248940e-01
5.67665047e-01 9.61564994e-01 7.58931873e-01 1.08989614e-02
7.69325529e-01 4.05955016e-01 1.98799935e-01 9.94134622e-01
3.07179216e-01 1.34756367e-01 2.92326855e-01 5.00026528e-01
7.23673231e-01 5.28698231e-01 1.52495715e-01 9.20139339e-01
1.76127500e-02 2.42244262e-01 7.09515862e-01 7.10358091e-01
6.47656449e-01 5.15623266e-01 8.77002211e-01 4.18744855e-01
9.67902538e-01 8.79261670e-01 5.88524781e-01 5.11397703e-02
7.07513737e-01 4.61998029e-01 8.77306226e-01 5.32049083e-01
8.07178697e-01 5.01521846e-04]
[1]
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.179.35