Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

indexerror: invalid index to scalar variable.

# You might be trying to index a scalar (non-iterable) value:

[y[1] for y in y_test]
#  ^ this is the problem

# When you call [y for y in test] you are iterating over the values already, so you get a single value in y.
# Your code is the same as trying to do the following:

y_test = [1, 2, 3]
y = y_test[0] # y = 1
print(y[0]) # this line will fail

# instead you could use a for loop:

for y in y_test:
    results.append(..., y)
 
PREVIOUS NEXT
Tagged: #invalid #index #scalar
ADD COMMENT
Topic
Name
9+9 =