# Week 2 Assignement 1 : stuck on implementation of logistic regression

I am currently doing assignment 1 and stucked on the part where we are writing code for calculating cost function .

1 - I am having an issue with understanding the shapes. Why features /elements are not considered as columns and number of examples as number of rows? Each row should be an example of data ?

2 - Can we calculate cost as A-Y

3 - Currently I stuck on an value error in section # GRADED FUNCTION: propagate

[code removed from Moderator]

There are a number of mistakes in your code. The top level problem is that you have all kinds of references to global variables like `train_x` inside your `propagate` code. That is a big mistake. You are also “hard-coding” the dimensions. That is also a mistake. We are trying to write general code here: just use the X and Y values that are passed in as parameters. You should never reference any variables in your functions other than the ones that are the parameters or local variables that you create. If you are not familiar with the concept of the “scope” of variables, you should seriously consider taking a python course first before you continue here.

For the arrangement of the data, there are multiple ways you can do it, but Prof Ng has chosen to arrange the X and Y input sample data and labels such that the “samples” dimension is the second dimension. This is a choice, but we have to understand and work with the choice he has made. So X has dimensions n_x x m, where n_x is the number of “features” or elements in each input vector and m is the number of sample inputs. Then Y will be 1 x m, because we only need one “label” value for each input.

For the cost, notice that A - Y is not the cost: it is the derivative dAL of the loss w.r.t. the activation A. It is used for computing the gradients, but not the cost. The formula for the cost is given in the instructions. Please have another look and read through all the instructions carefully and see if you have more followup questions.

Thank you for pointing out these mistakes, I’ll go through these concepts again and let you know if more questions arise.