Course5,Week1,prog2

I have a question about Exercise 2 - sample in Course5,Week1,prog2.
The input(x) is a column vector.In other words,there is only one example(not batch or mini_batch)
So the output(y) also should be a column vector,in other words,the shape of (length of vocabulary,1)
So we should not use y.ravel() to reshape y.

You’re right that y is a column vector of dimension 27 x 1 in this case. But try feeding that as the p argument to np.random.choice and see what happens. It throws an error, right? That’s just the way that API is built: it expects a 1D array as input and as the p parameter. There are other ways to achieve that besides using ravel(): np.squeeze also works fine. But just feeding it a 2D array does not work. Read the documentation for the random choice() function for more info.