December 2018
Beginner to intermediate
226 pages
7h 59m
English
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 ...
Read now
Unlock full access