I realize a lot of people have asked about this error, but I have yet to find anything that will help me.
This is my code:
def nanalyze(pupil, pw_sim):
import numpy as np
temp_s = abs(pw_sim)**2 * pupil
vals_x, vals_y = np.where(pupil > 0)
mask = pupil[vals_x[0]:vals_x[len(vals_x)-1], vals_y[0]:vals_y[len(vals_y)-1]]
s_i = (np.mean(temp_s[tuple(mask)]**2) / (np.mean(temp_s[tuple(mask)])**2)) - 1
return s_i
The second-to -last line,s_i = (np.mean(temp_s[tuple(mask)]**2) / (np.mean(temp_s[tuple(mask)])**2)) - 1, is what returns the index error: too many indices.
pupil and pw_sim are each arrays of shape (1024,1024). temp_s is therefore also a (1024,1024) array and mask ends up being a (1023,1023) array. I've tried making mask a (1024,1024) to check and see if I'm getting the index error just because of the difference in shapes, but that doesn't seem to change anything.
temp_s[tuple(mask)]?temp_susingmask. I translated this whole thing from Matlab code that had it astemp_s(mask).tuple- it can't be used as an index (to the best of my knowledge).temp_s[mask]and I got a different error saying I couldn't use mask as an index. I actually found a different question on this site which said that could be rectified by using atuple