Week 1 : Inference in code - error in video instruction

At 5 mins 36 secs into the video, Andrew presents this expression in Python using Numpy;

x = np.array([[0.0,...245,...240...0]])

which results in PyCharm displaying red squiggly lines.

This is incorrect syntax for creating an array using the Numpy module.

I would like to propose that it is corrected to avoid present and future students getting confused and perplexed.

Its simply not clear what this code does. Is it a 2-dimensional numpy array of 256 integer values, each representing a gray scale color value in the range 0 to 255? Or is it the 64 integer values from the image of the digit handwriting sample?

1 Like

Hi @ai_is_cool,

The syntax x = np.array([[0.0,...245,...240...0]]) is incorrect and would cause an error in Python.

In this part of the course, x should represent a flattened grayscale digit image while retaining its first dimension to allow for batch processing. The correct way to define x is:

x = np.array([[  0,  34, 128, 255, 200, 150,  23,   0,
                 0,  45, 210, 240, 180, 120,  50,   0,
                12, 100, 220, 255, 230, 140,  60,  10,
                 0,  30, 190, 250, 170, 110,  40,   0,
                 0,  20, 180, 245, 160, 100,  30,   0,
                 5,  70, 200, 255, 220, 130,  55,   5,
                 0,  40, 190, 240, 175, 115,  45,   0,
                 0,  10, 150, 230, 180,  90,  20,   0 ]])  # Shape (1, 64)

This ensures that x remains a 2D NumPy array with shape (1, 64), where the first dimension allows for future batches of digits. Each value in x represents a pixel intensity ranging from 0 to 255.
The primary goal of the video is likely to explain the concept, rather than to demonstrate executable Python code.

Here is the specific slide in question.

It seems fairly obvious that Andrew did not intend anyone to try to run this code, as he’s using an informal shorthand notation rather than write out a gigantic array of numbers.

Elementary familiarity with the Python language is assumed throughout all DLAI courses.

1 Like

What do you mean by “flattened” and “batch”.

These terms are not used by Andrew up to this point in Week 1.

Normally, an image is stored as a grid of pixel values. For example, an 8×8 grayscale image is a 2D array with 8 rows and 8 columns. “Flattening” an image means converting this grid into a single row of numbers. This is done because simple neural networks discussed in Week 1, expect the input to be a single row of numbers.

Instead of processing one example at a time, machine learning models usually process multiple examples together to improve efficiency.
A batch is a group of data examples that are processed at the same time.

1 Like

I’m confused why terms not used by Andrew are being introduced in this discussion by other members of the community as it doesn’t help to understand the content of the course up to this point when those terms are not defined by Andrew.

For other members of the community who have taken courses like CS229 or other Prof Ng’s courses in the past, it can sometimes be tricky to remember what was actually covered in the current course and what might be assumed based on previous knowledge.

1 Like

I’m confused because before I post my questions to the community I select the correct course and week number of the course so that contributors can refer back to that course and week number to ensure their contributions include only that course’s content.

Choosing the right course and week number helps a lot! Without it, we might risk veering into topics like convolutional neural networks or other terms that haven’t been covered yet, which would certainly add some unexpected complexity to the discussion.

Agreed.

So I am further confused why it is not clear to other members of the community which course and week my questions arise from before they attempt to answer my question.

Unfortunately, the reply button doesn’t show any constraints on terminology, so I guess it’s easy to just dive into answering without actually paying attention to the context.

I don’t understand.

I think it would be more useful to myself and other students if members of the community gave more careful consideration to the question and relevant course content that the student has selected before formulating an answer.

The concept of batch was introduced in the Coffee Roasting TF practical lab. And the concept of flattening was introduced in the first assignment. Course creators used the word “unrolled”, which means the same thing in this context. NumPy also uses the term flatten to describe converting a multi-dimensional array into a one-dimensional array.

1 Like

I see.

Thank you for that.

I will revise those elements of the course.

1 Like