I'm trying to run a for loop in python that looks like this:
data = np.linspace(0.5, 50, 10)
output = []
for i in data:
x = data[i] - data[i+1]
output.append(data)
but I keep getting the error:
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
For reference I want the code to do the following:
x1 = x = data[0] - data[1]
x2 = x = data[1] - data[2] ...
and output it to the list.
Any help would be really appreciated
for i in dataloops over the elements. You probably wantfor i,el in enumerate(data)