Vectorized NumPy Model Implementation code

Hi, I’d like to ask about this code.
x = X[0].reshape(-1,1)
z1 = np.matmul(x.T,W1) + b1
rather than this,
x = X[0], reshape(1,-1)
z1 = np. matmul(x,W1) + b1
Are there any reasons for that?

Hi @nerrad,

It is the MLS’s (also Tensorflow’s) convention to represent samples in that way.


Thank you for the reply and to make it clear, in this case, a single sample is represented as (400, 1) and the whole data set is represented as (10000, 400)?

Oh, sorry, @nerrad, I didn’t read the code carefully and thought it was for a dataset of one feature. The MLS convention for a dataset is (# samples, # features) for X, so the whole dataset is, yes, (10000, 400) for 10000 samples of 400 features.

Now, speaking of just one sample, obviously both your way and their way will work, and perhaps it is just a matter of preference, but I don’t know why they preferred their way but their way takes one more Transpose action than yours. (Maybe they want to stick to the image above?)


PS: I am going to edit my previous post.