Square of a vector?

Bhaiya told that square of a vector should be scalar in the closed form of Linear Regression video. but whenever I use numpy to make a square of vector it shows as a vector with individual elements squared ! So in what context did bhaiya told about the scalar output of vector square?

Hello @Mohit_Swain,

x*x where x is a numpy array gives you another array with element-wise multiplication. In literature, this operation is called an Hadamard product.

Here bhaiya told about scalar product, which is product of 2 vector elementwise then summing each elements giving you a scalar. To do this in numpy, you can either do the hadamard product first and sum up the resultant vector or simply compute the dot product of the vectors. Like this,

x2 = np.sum(x*x)

x2 = x.dot(x)

Happy Learning! :slight_smile:

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.