I am facing while Write a function to compute the square distance . please anyone tell me the code .

GRADED_FUNCTION: sq_dist

UNQ_C2

def sq_dist(a,b):
“”"
Returns the squared distance between two vectors
Args:
a (ndarray (n,)): vector with n features
b (ndarray (n,)): vector with n features
Returns:
d (float) : distance
“”"
### START CODE HERE ###
d=np.square(a)
d=d + np.square(b)
### END CODE HERE ###
return d

Please follow the formula marked (1). You need to find the difference between each element of vector a, and vector b, and then square the differences, and finally add those differences together to produce a single value.
To get the difference of each element between vector a and b, you can simply do a-b, resulting a vector of differences. You can then call np.square() with the differences vector as parameter, and finally, call np.sum() over the squared differences vector to produce a single value.

Hi everybody,
could you please help me with excercise 1 in this programming assignment?
I’ve seen the hints and solution, compared it to my code, but nevertheless I get back an error
I am attaching the screenshot if it helps.

The error message below indicates that you were referencing a variable called Model which had never been defined.

However, the line that triggered the problem isn’t part of the exercise, so I supposed you had somehow unintentionally modified it. You might just replace that line with the following:

model = tf.keras.Model([input_user, input_item], output)

Note that unless we had from tensorflow.keras import Model (which we havn’t), we need to use tf.keras.Model to reference to it (since we have import tensorflow as tf)

Cheers,
Raymond

PS: I will remove your code since we can’t share assignment code here. Next time, please just share a screenshot of just the error traceback.