A Selection of Present and Correct Error Messages

The "present" error messages here are real error messages which came up in actual Python code I wrote in Professor Andrew Ng's deeplearning.ai Coursera sequence of courses on Deep Learning.

Present Error Message 1:
---------------------------------------------------------------------------
in rnn_forward(x, a0, parameters)
     50     ### END CODE HERE ###
     51
    ===> 52     print("caches.shape: " + caches.shape)
     53
     54     # store values needed for backward propagation in cache

TypeError: must be str, not tuple

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in Line 52 of your code, the "caches.shape" variable should be enclosed by a "str()" function.

*****************************
Present Error Message 2:
---------------------------------------------------------------------------
in rnn_forward(x, a0, parameters)
     47     # Append "cache" to "caches" (1 line)
     48     caches = np.append( caches, cache )
    ===> 49     print("cache.shape: " + str(cache.shape))
     50     print("caches.shape: " + str(t) + " "+ str(caches.shape))
     51     ### END CODE HERE ###

AttributeError: 'tuple' object has no attribute 'shape'

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in Line 49 of your code, the variable "cache" is of type "tuple", and a tuple cannot be referenced by a "shape" attribute.

*****************************
Present Error Message 3:
---------------------------------------------------------------------------
in lstm_cell_forward(xt, a_prev, c_prev, parameters)
     33     print("sigmoid: ")
     34     a = [0]
    ===> 35     print(sigmoid(a))
     36     # Retrieve parameters from "parameters"
     37     Wf = parameters["Wf"]

/home/jovyan/work/Week 1/Building a Recurrent Neural Network - Step by Step/rnn_utils.py in sigmoid(x)
     7
     8     def sigmoid(x):
    ====> 9          return 1 / (1 + np.exp(-x))
     10
     11

TypeError: bad operand type for unary -: 'list'

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 9 of your code, the variable "x" is of type list, whereas it should be of type float.

*****************************
Present Error Message 4:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
     13     da_next = np.random.randn(5,10)
     14     gradients = rnn_cell_backward(da_next, cache)
    ===> 15     print("gradients[\"dxt\"][1][2] =", gradients["dxt"][1][2])
     16     print("gradients[\"dxt\"].shape =", gradients["dxt"].shape)
     17     print("gradients[\"da_prev\"][2][3] =", gradients["da_prev"][2][3])

TypeError: 'NoneType' object is not subscriptable

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 15 of your code, the variable "gradients" is of type None, because you have not assigned any value to it yet.

*****************************
Present Error Message 5:
---------------------------------------------------------------------------
in rnn_cell_backward(da_next, cache)
     33     print("da_next.shape: ", da_next.shape)
     34     print("Wax.T.dtanh: ", (np.dot(Wax.T, dtanh)).shape)
    ===> 35     dxt = np.dot( da_next, np.dot(Wax.T, dtanh))
     36     dWax = np.dot( dtanh, xt.T)
     37     print("dWax.shape: ", dWax.shape)

ValueError: shapes (5,10) and (3,10) not aligned: 10 (dim 1) != 3 (dim 0)

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 35 of your code, you are trying to take the product of two matrices whose dimensions are not matching.

*****************************
Present Error Message 6:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
     21     print("gradients[\"dWaa\"][1][2] =", gradients["dWaa"][1][2])
     22     print("gradients[\"dWaa\"].shape =", gradients["dWaa"].shape)
    ===> 23     print("gradients[\"dba\"][4] =", gradients["dba"][4])
     24     print("gradients[\"dba\"].shape =", gradients["dba"].shape)

IndexError: invalid index to scalar variable.

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 23 of your code, the variable gradients["dba"] is a scalar value, whereas you are trying to reference an array index from it.

*****************************
Present Error Message 7:
---------------------------------------------------------------------------
in rnn_backward(da, caches)
     19
     20     # Retrieve values from the first cache (t=1) of caches (2 lines)
    ===> 21     (caches, x) = None
     22     (a1, a0, x1, parameters) = None
     23

TypeError: 'NoneType' object is not iterable

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 21 of your code, you are assigning the value "None" to the tuple (caches, x), which is not allowed by Python.

*****************************
Present Error Message 8:
---------------------------------------------------------------------------
in rnn_backward(da, caches)
     20     # Retrieve values from the first cache (t=1) of caches (2 lines)
     21     (caches, x) = caches
    ===> 22     (a1, a0, x1, parameters) = caches[0]
     23
     24     # Retrieve dimensions from da's and x1's shapes (2 lines)

ValueError: too many values to unpack (expected 4)

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 22 of your code, the variable "caches[0]" is a tuple that is returning too many values to be assigned to the left hand side of the equation.

*****************************
Present Error Message 9:
---------------------------------------------------------------------------
in rnn_backward(da, caches)
     21     print("len-caches 0: ", len(caches))
     22     (caches, x) = caches
    ===> 23     print("len-caches 1: ", len(caches[0][0][0]))
     24     (a1, a0, x1, parameters) = caches[0]
     25

TypeError: object of type 'numpy.float64' has no len()

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 23 of your code, you are calling the function "len" on the variable caches[0][0][0], which is a float value, which is not allowed by Python.

*****************************
Present Error Message 10:
---------------------------------------------------------------------------
in rnn_cell_backward(da_next, cache)
     17
     18     # Retrieve values from cache
    ===>19     (a_next, a_prev, xt, parameters) = cache
     20
     21     # Retrieve values from parameters

ValueError: too many values to unpack (expected 4)

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 19 of your code, the variable "cache" is a tuple that is returning too many values to be assigned to the left hand side of the equation.

*****************************
Present Error Message 11:
---------------------------------------------------------------------------
in rnn_backward(da, caches)
     42     # Increment global derivatives w.r.t parameters by adding their derivative at time-step t
     43     dx[:, :, t] = dxt
    ===> 44     dWax += dWaxt
     45     dWaa += dWaat
     46     dba += dbat

ValueError: operands could not be broadcast together with shapes (5,10) (5,3) (5,10)

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 44 of your code, the variables "dWax" and "dWaxt" are matrices which are of different dimensions.

*****************************
Present Error Message 12:
---------------------------------------------------------------------------
line 38
     dcct = dc_next * it *
                                     ^
SyntaxError: invalid syntax

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 38 of your code, after the last * in the line, you need another number.

*****************************
Present Error Message 13:
---------------------------------------------------------------------------
     21     dc_next = np.random.randn(5,10)
     22     gradients = lstm_cell_backward(da_next, dc_next, cache)
    ===> 23     print("gradients[\"dxt\"][1][2] =", gradients["dxt"][1][2])
     24     print("gradients[\"dxt\"].shape =", gradients["dxt"].shape)
     25     print("gradients[\"da_prev\"][2][3] =", gradients["da_prev"][2][3])

TypeError: 'NoneType' object is not subscriptable

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 23 of your code, the variable 'gradients["dxt"]' is of type None, and you cannot index into a None object.

*****************************
Present Error Message 14:
---------------------------------------------------------------------------
in lstm_cell_backward(da_next, dc_next, cache)
     49
     50     # Compute parameters related derivatives. Use equations (11)-(14) (8 lines)
    ===> 51     concat = (np.concatenate(a_prev,xt)).T
     52     print("concat shape: ", concat.shape)
     53     dWf = None

TypeError: only length-1 arrays can be converted to Python scalars

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 51 of your code, the np.concatenate function needs two sets of braces around the list of matrices to be concatenated.

*****************************
Present Error Message 15:
---------------------------------------------------------------------------
in lstm_cell_backward(da_next, dc_next, cache)
     52     print("concat shape: ", concat.shape)
     53     print("dft.shape: ", dft.shape)
    ===> 54     dWf = dft * concat
     55     dWi = None
     56     dWc = None

ValueError: operands could not be broadcast together with shapes (5,10) (10,8)

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 54 of your code, the variables dft and concat are matrices of different dimensions, and hence cannot be multiplied together.

*****************************
Present Error Message 16:
---------------------------------------------------------------------------
in lstm_backward(da, caches)
     25     # Retrieve values from the first cache (t=1) of caches.
     26     (caches, x) = caches
    ===> 27     (a1, c1, a0, c0, f1, i1, cc1, o1, x1, parameters) = caches[0]
     28
     29     ### START CODE HERE ###

ValueError: not enough values to unpack (expected 10, got 5)

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 27 of your code, the variable "caches[0]" does not have enough values to assign to the tuple on the left hand side of the equation.

*****************************
Present Error Message 17:
---------------------------------------------------------------------------
in lstm_backward(da, caches)
     33     print("da.shape: ", da.shape)
     34     print("x1.shape: ", x1.shape)
    ===> 35     n_a, m, T_x = None
     36     n_x, m = None
     37

TypeError: 'NoneType' object is not iterable

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 35 of your code, the tuple on the left hand side of the equation cannot be assigned a "None" value.

*****************************
Present Error Message 18:

line 17
        print("pair: pair)
                                ^
SyntaxError: EOL while scanning string literal

Correct Error Message: Sandeep, I'm having a problem interpreting your code. I believe the problem is that in line 17 of your code, you have not closed a quote mark.

*****************************