Linalg.l2_normalize function in C3_W2_RecSysNN_Assignment

Hi all.
I have completed C3_W2_RecSysNN_Assignment and wanting to experiment further with the lab. However, while re-watching Prof. Andrew Ng’s explanation on the tensorflow implementation of the model, I didn’t fully understand the mentioned function linalg.l2_normalize.

In the video the professor mentioned that the function “normalizes the vector vu to have length one”. But when I check the documentation tf.math.l2_normalize | TensorFlow v1.15.0 it says the function returns " A Tensor with the same shape as x." Therefore, to my understanding, there is a difference in the return vector size based on these 2 sources.
I’m aware that the documentation is for math.l2_normalize, not linalg.l2_normalize, but I can’t find the official document for linalg.l2_normalize (maybe because it’s for the older version of Tensorflow?) and I’m assumming they are quite similar.
So my question is why is the difference in the return vector length/size? And why should I use this function in the first place in my personal future projects?
Thank you!

Hello @HueyVu,

The meaning of a vector’s “length” here is not equal to the meaning of vector’s “shape”. For example, the vector [ 1, 2, 3 ] has a shape of (3, ) but a vector length of \sqrt{1^2 + 2^2 + 3^2} where the length here is defined as the vector’s L2 norm. It is also why the function’s name carries the term “l2_normalize”. Try to apply the tf.math.l2_normalize to a vector or an array and see it for yourself what its length and shape will become afterwards.


Thank you for the clarification!

A post was split to a new topic: C3 W2 RecSysNN Assignment problem