C1_W1_Lab02_Model Rep - m = x.shape[0]?

Hello! I’ve been stuck for a while, so I hope you geniuses out there can help me :slight_smile:

In the def compute_model_output(x, w, b) function (pic 1), I am quite confused about why we are using m = x.shape[0], not m = x_train.shape[0]? We literally JUST initiated x in the def(), so where would the program find “the shape of x” to assign to m? In the lines preceding it, we had defined the array as x_train = np.array([1.0, 2.0]), so x_train.shape[0] seems to more sense to me.

Can someone let me know what I’m missing? Thanks a bunch!

I think you need some python classes to undestand how coding and more specifically python works.

When you build a a function in python;

def my_function(arg1, arg2, arg3…)

the variables used within the definition and in the body of the function, are just mock ups that will later store the parameters that you feed when you initiate the function itself i.e.

calling the function

output = my_function(x_train.shape[0], x_train.shape[1],…).

I hope you understand.

1 Like

No, that’s not what a function parameter does. It doesn’t initialize anything. It’s just a ‘container’ that passes data into the function.

Inside the function, the code can then use whatever attributes came along with the data when the function was called.

The reason function parameters are handled this way is that you can write a general function that uses whatever data you need in a specific situation.

Think of a function like a hammer. You can use it to drive any sort of compatible nail. You don’t need a special hammer for every individual nail.

1 Like

Yes, I understand! Thanks a bunch! And totally agree I that I should work on my python in parallel :nerd_face: :nerd_face:

1 Like

Thanks for pointing the difference between “initializing” and “being a container” for me! It helps! :nerd_face:

1 Like