Week1 lab03

In the function my_predict(), why p is defined as np.zeros((m,1)) instead of np.zeros(m)? Also to be consistent, when yhat = np.zeros_like(predictions), why in the last cell in the screenshot, it is yhat[i], instead of yhat[i,0] like in the first cell, it is p[i,0].

The two notations will give different shapes. The author preferred the first shape.

Both methods will give the same results. The author was a little careless in their notation.

HI TMosh,

  1. do you mean both methods( p is defined as np.zeros((m,1)) & np.zeros(m)) are correct?
  2. since predictions is 2D, so yhat is also 2D. Why using yhat[i] will give same result as yhat[i,0] instead of having shape error?

Both methods can be used. Whether either is “correct” depends on your standard of correctness.

I’m going to guess that Python is doing some conversion automatically.