I realize a lot of people have asked about this error, but I have yet to find anything that will help me. I'm new to Python and working on some pretty high-level simulations, so up until now this website has been my best friend - now I could really use some help figuring out how to fix this error.
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. I cannot figure out what the problem is!
Aucun commentaire:
Enregistrer un commentaire