I am new to using the numpy class and I am having problems with manipulating the contents of the array. Here is the code:
# finance equation to apply to each element of array
for row in cum_ret:
for col in row:
if sum(row)!=0:
row[col] = prev_row[col]*(1+row[col])
else:
row[col] = 1
cum_ret[row][col] = row[col]
prev_row = row
# see changed contents
for row in cum_ret:
print row
Now I am getting an error saying that array indices used must be of integer or boolean type. I get it because the 'row' value is also an array so it can't index an array object. So what is the correct syntax for doing this, or is their a method I am supposed to use?
Thank in advance
The cum_ret array is a 2d ndarray of float64s and is the array I want to modify. Here is a short snippet of the output:
[[ 0. 0. 0. 0. 0. ]
[ 0.00046187 0.00836672 0.00020435 -0.00048292 0.00342209]
[-0.07633505 -0.00514199 -0.04133778 -0.02450642 -0.01865075]
...,
[ 0.01229435 0.00175341 0.00709808 0.00213371 0.0061171 ]
[-0.0118614 -0.00994933 -0.00557095 -0.00141945 -0.00347423]
[ 0.01214725 -0.00502466 0.00537611 -0.00035537 -0.00101685]]
And here is were it is occurring:
Traceback (most recent call last):
File "qstk1.py", line 37, in <module>
cum_ret[row][col] = row[col]
IndexError: arrays used as indices must be of integer (or boolean) type
cum_ret? Where exactly is the error occurring? What's the stack trace?