Confused with Programming assignment

Hi @reinhardt_scott,
In regard to your question 1, I am referencing the instruction below:

2 - Overview of the Problem set

Problem Statement: You are given a dataset (“data.h5”) containing:

- a training set of m_train images labeled as cat (y=1) or non-cat (y=0)
- a test set of m_test images labeled as cat or non-cat
- each image is of shape (num_px, num_px, 3) where 3 is for the 3 channels (RGB). Thus, each image is square (height = num_px) and (width = num_px).

Here, num_px is number of pixels in a image. As each image has the same number of pixel for the width and height, so it is a square image. In this exercise, both the training set and test set use images of the same size,
whether num-px is taken from the training set or test set would still give you the correct answer. However, it would be more appropriate to get num_px from the training set. Similarly, it doesn’t matter if you get the num_px from train_set_x_orig.shape[1] or train_set_x_orig.shape[2].

For your second question, what it means is that you need to change the array representation of the image from an array of size (num_px, num_px,3) into a single vector of size (num_px * num_px, 1), here the ‘*’ is the multiplication operator.

To do that, you are given a hind to use the X.reshape() function. Here, the X represent the dataset you are interested in. So if you want to flatten the training dataset, this is what it would look like:
train_set_x_flatten =train_set_x_orig.reshape(train_set_x_orig.shape[0], -1).T
You may find this thread helpful: W 2 A1 | Exercise 2 : X_flatten = X.reshape(X.shape[0], -1).T? - Deep Learning Specialization / Neural Networks and Deep Learning - DeepLearning.AI

2 Likes