I am trying to get it so my list starts at zero rather than the large number it originally starts at. To do this, I will have to subtract the initial value from all the other values in the list. The numbers in the list are floating-point and fairly large numbers. I need to somehow subtract the initial time from all other times. I have tried a few things which are here:
for index, time in enumerate(STARTTIME_MAX1):
time = time/60
#if time > 0:
# time = time - time[0]
time = time - time[0]
#time[:] = [time - time[0] for time in STARTTIME_MAX1]
STARTTIME_MAX1[index] = time
I also tried this way:
for time in STARTTIME_MAX1:
time = time/60
time = time-time[0]
print(time)
print(STARTTIME_MAX1)
and tried this:
STARTTIME_MIN = [((i/60)-i[0]) for i in STARTTIME_MAX1]
But every time I am getting an error: TypeError: 'float' object is not subscriptable
.
I need to keep the values as floating-point so they are more exact. STARTTIME_MAX1 is just a list of measurement starting times, and I need to subtract the first starttime value from all the values in the list so that it starts at an initial time of zero and continues up from there. Any help would be greatly appreciated!
For simplicity, let's say you have a list like this:
a = [15, 16, 17, 19]
And you want to subtract the first value, 15:
a = [0, 1, 2, 4]
To get the first element, you can use a[0]
, then you can subtract it from every element including itself. Here I'll use a comprehension with a full-slice-assignment.
initial = a[0]
a[:] = [x-initial for x in a]
# > a = [0, 1, 2, 4]