简体   繁体   中英

IndexError: Too many indices in array python numpy

I am creating an export for a classifier model and some rescaling values. With the guidance of a PhD student that studies the field, he provided me with code that creates a rescaling dictionary for us to use. The relevant code:

PROBA_RESCALING_N_SAMPLES = 100
PROBA_RESCALING_WINDOW_RADIUS = 0.05
y_proba = classifier.predict_proba(x)
y_proba_rescaling = {proba: y[np.abs(y_proba - proba) <= PROBA_RESCALING_WINDOW_RADIUS].mean() for proba in np.linspace(0, 1, PROBA_RESCALING_N_SAMPLES)}

The error occurs at the last line, and it says:

IndexError: too many indices for array

I looked over the forums here for some answers,and sat with a friend for over an hour and still I couldn't understand why that error was caused. Yesterday the code seemed fine, and suddenly today it is bugged.

EDIT : I have missed a couple of important details that I forgot to mention:
1. the Y variable is an array that contains zeros and ones, it represents the Y axis in my dataset for the ML learning.
2. I have narrowed down the problem to the y[np.abs(y_proba - proba) <= PROBA_RESCALING_WINDOW_RADIUS] part. Running it on its own produces the error.

y[np.abs(y_proba - proba) <= PROBA_RESCALING_WINDOW_RADIUS]

Do you mean:

y[np.abs(y_proba - proba)] <= PROBA_RESCALING_WINDOW_RADIUS

Where the bracket spot changed? You are indexing a comparison in Y list. It doesn't quite make sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM