How about this vectorization implementation

I am thinking of ways to avoid so many loops in my code. I figure if I only have to loop over the length n instead of n and m then I am in a better place computationally.

I have drawn out what I mean:

Any opinions? Does this have any benefit?

Hi Jesse,

I just wrote two functions doing simple vector addition to create a new array (length 10000) each with simple integer elements. The first approach using a for loop was about 1000x slower (using %timeit in jupyter) than using a vectorized approach (of x+y ). So if that was only for simple vector addition, you can imagine how much faster the vectorized approach is for multiplication, particularly for larger and larger objects. My guess is that in all cases for loops would be less desirable, but someone can correct me if I’m wrong…

No loops are necessary. is your friend.

So you are doing a dot product between \vec{w} and \vec{x} so there is no need to loop over n and this is an improvement to computational efficiency, and because you calculate all \hat{y}^{(i)} one by one and this requires to loop over m which is the next improvement you can make. Then you end by dotting the error vector and the feature vector. :+1: