I haven't used numpy much and am struggling to figure out the vectorized implementation of the following:
Change and pct_change are numpy arrays which are 5*2000 in size.
I wanted to calculate each element in the array Change_after_calculation like:
###Carry out this calculation for each number
###in Change_after_calculation where Change has a correspondingly -ve number
Change_after_calculation = (numpy.ones((5,2000)) + pct_change) * Change
###If Change has a correspondingly +ve number do the below
Change_after_calculation = Change
I could do the above with multiple for loops like this, but if there is a vectorized way to do it, I'd prefer to do that:
for p in 2000:
for n in 5:
if Change[n,p] < 0:
Change_after_calculation[n,p] = (1+pct_change[n,p]) * Change[n,p]
else:
Change_after_calculation[n,p] = Change[n,p]