NorGer
NorGer

Reputation: 67

Python IndexError: invalid index to scalar variable

Why do i get the indexError?

I have tried to change the slicing to 2001 but i did not help

inputs = training_data[:-1] #EVERYTHING EXCEPT last values
outputs = training_data[-1] #last value

training_inputs = inputs[:2000]
training_outputs = outputs[:2000]
testing_inputs = inputs[2000:]
testing_outputs = outputs[2000:]

IndexError: invalid index to scalar variable.

Upvotes: 0

Views: 2710

Answers (2)

Massifox
Massifox

Reputation: 4487

Because output is not a list, and therefore it is not possible to perform slice operations. If you want output to be a list you can use this trick:

outputs = training_data[-1:]

Upvotes: 1

Sai prateek
Sai prateek

Reputation: 11906

This problem occurs when You are trying to index into a scalar non-iterable value.

>> data = [3, 6, 9]
>> result = data[0] # gives you result=3
>> print(result[0]) # Error

Upvotes: 2

Related Questions