I was trying to take advantage of the Broadcasting property of Python while replacing the for loop of this snippet:
import numpy as np
B = np.random.randn(10,1)
k = 25
for i in range(len(B)):
B[i][0]= B[i][0] + k
with this:
for i in range((lenB)):
B=B+k
I observed that I was getting different results. When I tried outside the loop, B = B+k, gave the same results as what I was expecting with B[i][0] = B[i][0] + k
Why is this so? Does Broadcasting follow different rules inside loops?