Shape of one_hot

Hi all

Why is one_hot_matrix producing rows of 0 and 1s isntead of columns? I thought the shape of Y should be num_classes x training examples, as we have ALWAYS had training exampeles in each column. This is really confusing.

It looks like the instructions are not really correct that we want a “columnwise” matrix here. If you specify the output shape as [depth,1], the unit test throws an error and it also doesn’t work with the later logic that uses one_hot_matrix. What is really happening here is that we are creating 1D vectors, which don’t really have a row or column orientation.

1 Like

I have a problem with the reshape part. When we use the map(one_hot_matrix) on the Y_train and Y_test, as evident in the image I posted, one training example is a row, not a column. Should each training example not be a column? Why does it look like a row in the output? Is it not a row, but just looks like a row?

Well, actually, it’s a 1D tensor, meaning it literally has only one dimension. So the idea of “row” or “column” doesn’t even make sense. It’s just a “vector”. The other thing to note is that while Prof Ng uses the convention that the “samples” dimension is last, TF/Keras does the opposite with the “samples” dimension being first. They only briefly mention this in the instructions for the upcoming compute_cost function, but we’ll need to do transposes to get things into the correct format.

1 Like