LinAlgError: Last 2 dimensions of the array must be square

I’m getting this error on C1_W3_Assignment

I didn’t change anything was just running cost function.

print("cost = " + str(compute_cost(Y_hat, Y)))   

Error:

---------------------------------------------------------------------------
LinAlgError                               Traceback (most recent call last)
<ipython-input-32-527ef46af1ee> in <module>
----> 1 print("cost = " + str(compute_cost(Y_hat, Y)))

<ipython-input-31-bd054509b831> in compute_cost(Y_hat, Y)
     15 
     16     # Compute the cost function.
---> 17     cost = np.sum((Y_hat - Y)**2)/(2*m)
     18 
     19     return cost

/opt/conda/lib/python3.8/site-packages/numpy/matrixlib/defmatrix.py in __pow__(self, other)
    229 
    230     def __pow__(self, other):
--> 231         return matrix_power(self, other)
    232 
    233     def __ipow__(self, other):

<__array_function__ internals> in matrix_power(*args, **kwargs)

/opt/conda/lib/python3.8/site-packages/numpy/linalg/linalg.py in matrix_power(a, n)
    618     a = asanyarray(a)
    619     _assert_stacked_2d(a)
--> 620     _assert_stacked_square(a)
    621 
    622     try:

/opt/conda/lib/python3.8/site-packages/numpy/linalg/linalg.py in _assert_stacked_square(*arrays)
    201         m, n = a.shape[-2:]
    202         if m != n:
--> 203             raise LinAlgError('Last 2 dimensions of the array must be square')
    204 
    205 def _assert_finite(*arrays):

LinAlgError: Last 2 dimensions of the array must be square

And i’m getting zero points even though Unit test showed that all answers above cost function where correct…

I have figured it out…

i had an error on initialize_parameters which was not caught by the unit test.

1 Like