Hi In The #Week 3 Assigment i Have tried my code in 2 different method Gettin wrpng in np.dot methos can someone clarify please

week-3
#Coursera | Online Courses & Credentials From Top Educators. Join for Free | Coursera

{mentor edit: code removed}

Getting error

#Getting correct answer in this code

{mentor edit: code removed}

Please do not post your code on the forum. That’s not allowed by the Code of Conduct.

If a mentor needs to see your code, we’ll contact you with instructions.

You can post any error messages or asserts, those are usually sufficient to identify a problem.

I’ll edit your message to remove the code.

Hints:

  • Use your sigmoid() function, don’t duplicate the code inside the propagate() function.
  • Check your parenthesis grouping, the multiplication by -1/m needs to apply to the entire sum.
1 Like

This code is indeed correct. What is your question?

While using np.dot in cost it’s coming as error

There are several ways to compute the A and cost values.

  • np.dot can be used in both computing A and cost.

  • If you use np.dot in computing the cost, you do not need to use np.sum(). The dot product automatically computes the sum.

I am getting the error show in the image on computing cost with np.dot

Should I do with transpose?

It depends on the shapes and order of the arguments.

Use a print() statement to investigate the shapes.

It requires that you understand how dot products work. The key point is that the “inner” dimensions need to agree. So with two 1 x 3 objects, you have two choices:

1 x 3 dot 3 x 1 yields a 1 x 1 or scalar output
3 x 1 dot 1 x 3 yields a 3 x 3 output

Here’s a thread which talks about this choice and gives examples to demonstrate that those two give very different results.

One other important thing to understand is about how the notebooks work: if you type new code into a function cell and then run the test that calls that function again, it does nothing. It just ends up running the old code again. In order to get your newly entered code “activated” or compiled, you need to either click “Shift-Enter” on the changed cell before you call it again or you can restart everything by doing:

Kernel → Restart and Clear Output
Cell → Run All

That will get everything back in sync again and WYSIWYG.

Oh Got it Thank y all for solving it .

2 Likes